doc/tutorials/base/customizing-the-application.rst
changeset 12367 77342fae06fb
parent 12366 72ba5f5278e0
child 12368 feb60b438c1b
equal deleted inserted replaced
12366:72ba5f5278e0 12367:77342fae06fb
   252 
   252 
   253 .. sourcecode:: python
   253 .. sourcecode:: python
   254 
   254 
   255   from cubicweb.web.views import basetemplates
   255   from cubicweb.web.views import basetemplates
   256 
   256 
       
   257 
   257   class MyHTMLPageFooter(basetemplates.HTMLPageFooter):
   258   class MyHTMLPageFooter(basetemplates.HTMLPageFooter):
   258 
   259 
   259       def footer_content(self):
   260       def footer_content(self):
   260 	  self.w(u'This website has been created with <a href="http://cubicweb.org">CubicWeb</a>.')
   261           self.w(u'This website has been created with <a href="http://cubicweb.org">CubicWeb</a>.')
       
   262 
   261 
   263 
   262   def registration_callback(vreg):
   264   def registration_callback(vreg):
   263       vreg.register_all(globals().values(), __name__, (MyHTMLPageFooter,))
   265       vreg.register_all(globals().values(), __name__, (MyHTMLPageFooter,))
   264       vreg.register_and_replace(MyHTMLPageFooter, basetemplates.HTMLPageFooter)
   266       vreg.register_and_replace(MyHTMLPageFooter, basetemplates.HTMLPageFooter)
   265 
   267 
   311 .. sourcecode:: python
   313 .. sourcecode:: python
   312 
   314 
   313   from cubicweb.predicates import is_instance
   315   from cubicweb.predicates import is_instance
   314   from cubicweb.web.views import primary
   316   from cubicweb.web.views import primary
   315 
   317 
       
   318 
   316   class CommunityPrimaryView(primary.PrimaryView):
   319   class CommunityPrimaryView(primary.PrimaryView):
   317       __select__ = is_instance('Community')
   320       __select__ = is_instance('Community')
   318 
   321 
   319       def cell_call(self, row, col):
   322       def cell_call(self, row, col):
   320           entity = self.cw_rset.get_entity(row, col)
   323           entity = self.cw_rset.get_entity(row, col)
   321           self.w(u'<h1>Welcome to the "%s" community</h1>' % entity.printable_value('name'))
   324           self.w(u'<h1>Welcome to the "%s" community</h1>' % entity.printable_value('name'))
       
   325 
   322           if entity.description:
   326           if entity.description:
   323               self.w(u'<p>%s</p>' % entity.printable_value('description'))
   327               self.w(u'<p>%s</p>' % entity.printable_value('description'))
   324 
   328 
   325 What's going on here?
   329 What's going on here?
   326 
   330 
   420       __select__ = is_instance('Community')
   424       __select__ = is_instance('Community')
   421 
   425 
   422       def cell_call(self, row, col):
   426       def cell_call(self, row, col):
   423           entity = self.cw_rset.get_entity(row, col)
   427           entity = self.cw_rset.get_entity(row, col)
   424           self.w(u'<h1>Welcome to the "%s" community</h1>' % entity.printable_value('name'))
   428           self.w(u'<h1>Welcome to the "%s" community</h1>' % entity.printable_value('name'))
       
   429 
   425           if entity.display_cw_logo():
   430           if entity.display_cw_logo():
   426               self.w(u'<img src="https://docs.cubicweb.org/_static/logo-cubicweb-small.svg"/>')
   431               self.w(u'<img src="https://docs.cubicweb.org/_static/logo-cubicweb-small.svg"/>')
       
   432 
   427           if entity.description:
   433           if entity.description:
   428               self.w(u'<p>%s</p>' % entity.printable_value('description'))
   434               self.w(u'<p>%s</p>' % entity.printable_value('description'))
   429 
   435 
   430 Then each community whose description contains 'CW' is shown with the |cubicweb|
   436 Then each community whose description contains 'CW' is shown with the |cubicweb|
   431 logo in front of it.
   437 logo in front of it.
   473   class comments(RelationDefinition):
   479   class comments(RelationDefinition):
   474       subject = 'Comment'
   480       subject = 'Comment'
   475       object = 'BlogEntry'
   481       object = 'BlogEntry'
   476       cardinality = '1*'
   482       cardinality = '1*'
   477       composite = 'object'
   483       composite = 'object'
       
   484 
   478 
   485 
   479   class tags(RelationDefinition):
   486   class tags(RelationDefinition):
   480       subject = 'Tag'
   487       subject = 'Tag'
   481       object = ('Community', 'BlogEntry')
   488       object = ('Community', 'BlogEntry')
   482 
   489 
   517 
   524 
   518   class CommunityPrimaryView(primary.PrimaryView):
   525   class CommunityPrimaryView(primary.PrimaryView):
   519       __select__ = is_instance('Community')
   526       __select__ = is_instance('Community')
   520 
   527 
   521       def render_entity_title(self, entity):
   528       def render_entity_title(self, entity):
   522 	  self.w(u'<h1>Welcome to the "%s" community</h1>' % entity.printable_value('name'))
   529           self.w(u'<h1>Welcome to the "%s" community</h1>' % entity.printable_value('name'))
   523 
   530 
   524       def render_entity_attributes(self, entity):
   531       def render_entity_attributes(self, entity):
   525 	  if entity.display_cw_logo():
   532           if entity.display_cw_logo():
   526 	      self.w(u'<img src="https://docs.cubicweb.org/_static/logo-cubicweb-small.svg"/>')
   533               self.w(u'<img src="https://docs.cubicweb.org/_static/logo-cubicweb-small.svg"/>')
   527 	  if entity.description:
   534 
   528 	      self.w(u'<p>%s</p>' % entity.printable_value('description'))
   535           if entity.description:
       
   536               self.w(u'<p>%s</p>' % entity.printable_value('description'))
   529 
   537 
   530 It appears now properly:
   538 It appears now properly:
   531 
   539 
   532 .. image:: ../../images/tutos-base_myblog-community-taggable-primary_en.png
   540 .. image:: ../../images/tutos-base_myblog-community-taggable-primary_en.png
   533    :alt: the custom primary view for a community entry with tags activated
   541    :alt: the custom primary view for a community entry with tags activated