doc/book/devrepo/vreg.rst
changeset 12879 7347715bf0ee
parent 10499 d0907690af55
equal deleted inserted replaced
12878:ec05a333f02c 12879:7347715bf0ee
   298 Here is a quick example:
   298 Here is a quick example:
   299 
   299 
   300 .. sourcecode:: python
   300 .. sourcecode:: python
   301 
   301 
   302     class UserLink(component.Component):
   302     class UserLink(component.Component):
   303 	'''if the user is the anonymous user, build a link to login else a link
   303         '''if the user is the anonymous user, build a link to login else a link
   304 	to the connected user object with a logout link
   304         to the connected user object with a logout link
   305 	'''
   305         '''
   306 	__regid__ = 'loggeduserlink'
   306         __regid__ = 'loggeduserlink'
   307 
   307 
   308 	def call(self):
   308         def call(self):
   309 	    if self._cw.session.anonymous_session:
   309             if self._cw.session.anonymous_session:
   310 		# display login link
   310                 # display login link
   311 		...
   311                 ...
   312 	    else:
   312             else:
   313 		# display a link to the connected user object with a loggout link
   313                 # display a link to the connected user object with a loggout link
   314 		...
   314                 ...
   315 
   315 
   316 The proper way to implement this with |cubicweb| is two have two different
   316 The proper way to implement this with |cubicweb| is two have two different
   317 classes sharing the same identifier but with different selectors so you'll get
   317 classes sharing the same identifier but with different selectors so you'll get
   318 the correct one according to the context.
   318 the correct one according to the context.
   319 
   319 
   320 .. sourcecode:: python
   320 .. sourcecode:: python
   321 
   321 
   322     class UserLink(component.Component):
   322     class UserLink(component.Component):
   323 	'''display a link to the connected user object with a loggout link'''
   323         '''display a link to the connected user object with a loggout link'''
   324 	__regid__ = 'loggeduserlink'
   324         __regid__ = 'loggeduserlink'
   325 	__select__ = component.Component.__select__ & authenticated_user()
   325         __select__ = component.Component.__select__ & authenticated_user()
   326 
   326 
   327 	def call(self):
   327         def call(self):
   328             # display useractions and siteactions
   328             # display useractions and siteactions
   329 	    ...
   329             ...
   330 
   330 
   331     class AnonUserLink(component.Component):
   331     class AnonUserLink(component.Component):
   332 	'''build a link to login'''
   332         '''build a link to login'''
   333 	__regid__ = 'loggeduserlink'
   333         __regid__ = 'loggeduserlink'
   334 	__select__ = component.Component.__select__ & anonymous_user()
   334         __select__ = component.Component.__select__ & anonymous_user()
   335 
   335 
   336 	def call(self):
   336         def call(self):
   337 	    # display login link
   337             # display login link
   338             ...
   338             ...
   339 
   339 
   340 The big advantage, aside readability once you're familiar with the
   340 The big advantage, aside readability once you're familiar with the
   341 system, is that your cube becomes much more easily customizable by
   341 system, is that your cube becomes much more easily customizable by
   342 improving componentization.
   342 improving componentization.