doc/book/en/development/webstdlib/primary.rst
branchstable
changeset 3258 6536ee4f37f7
parent 2545 f8246ed962f6
child 4430 0b6a069eb29e
equal deleted inserted replaced
3257:0d953f0b41c4 3258:6536ee4f37f7
     7 This view is supposed to render a maximum of informations about the entity.
     7 This view is supposed to render a maximum of informations about the entity.
     8 
     8 
     9 Rendering methods and attributes for ``PrimaryView``
     9 Rendering methods and attributes for ``PrimaryView``
    10 ----------------------------------------------------
    10 ----------------------------------------------------
    11 
    11 
    12 By default, *CubicWeb* provides a primary view for each new entity type
    12 By default, *CubicWeb* provides a primary view for every available
    13 you create. The first view you might be interested in modifying.
    13 entity type. This is the first view you might be interested in
       
    14 modifying.
    14 
    15 
    15 Let's have a quick look at the EntityView ``PrimaryView`` as well as
    16 Let's have a quick look at the EntityView ``PrimaryView`` as well as
    16 its rendering method
    17 its rendering method
    17 
    18 
    18 .. sourcecode:: python
    19 .. sourcecode:: python
    22         id = 'primary'
    23         id = 'primary'
    23         title = _('primary')
    24         title = _('primary')
    24         show_attr_label = True
    25         show_attr_label = True
    25         show_rel_label = True
    26         show_rel_label = True
    26         skip_none = True
    27         skip_none = True
    27         skip_attrs = ('eid', 'creation_date', 'modification_date')
    28         rsection = uicfg.primaryview_section
    28         skip_rels = ()
    29         display_ctrl = uicfg.primaryview_display_ctrl
    29         main_related_section = True
    30         main_related_section = True
    30 
    31 
    31         ...
    32         ...
    32 
    33 
    33     def cell_call(self, row, col):
    34     def cell_call(self, row, col):
    34         self.row = row
    35         self.row = row
    35         self.render_entity(self.complete_entity(row, col))
    36         self.maxrelated = self.req.property_value('navigation.related-limit')
       
    37         entity = self.complete_entity(row, col)
       
    38         self.render_entity(entity)
    36 
    39 
    37     def render_entity(self, entity):
    40     def render_entity(self, entity):
    38         """return html to display the given entity"""
       
    39         siderelations = []
       
    40         self.render_entity_title(entity)
    41         self.render_entity_title(entity)
    41         self.render_entity_metadata(entity)
    42         self.render_entity_metadata(entity)
    42         # entity's attributes and relations, excluding meta data
    43         # entity's attributes and relations, excluding meta data
    43         # if the entity isn't meta itself
    44         # if the entity isn't meta itself
    44         self.w(u'<div>')
    45         boxes = self._prepare_side_boxes(entity)
       
    46         if boxes or hasattr(self, 'render_side_related'):
       
    47             self.w(u'<table width="100%"><tr><td style="width: 75%">')
       
    48         self.render_entity_summary(entity)
    45         self.w(u'<div class="mainInfo">')
    49         self.w(u'<div class="mainInfo">')
    46         self.render_entity_attributes(entity, siderelations)
       
    47         self.w(u'</div>')
       
    48         self.content_navigation_components('navcontenttop')
    50         self.content_navigation_components('navcontenttop')
       
    51         self.render_entity_attributes(entity)
    49         if self.main_related_section:
    52         if self.main_related_section:
    50             self.render_entity_relations(entity, siderelations)
    53             self.render_entity_relations(entity)
    51         self.w(u'</div>')
    54         self.w(u'</div>')
    52         # side boxes
    55         # side boxes
    53         self.w(u'<div class="primaryRight">')
    56         if boxes or hasattr(self, 'render_side_related'):
    54         self.render_side_related(entity, siderelations)
    57             self.w(u'</td><td>')
    55         self.w(u'</div>')
    58             self.w(u'<div class="primaryRight">')
    56         self.w(u'<div class="clear"></div>')
    59             if hasattr(self, 'render_side_related'):
       
    60                 warn('render_side_related is deprecated')
       
    61                 self.render_side_related(entity, [])
       
    62             self.render_side_boxes(boxes)
       
    63             self.w(u'</div>')
       
    64             self.w(u'</td></tr></table>')
    57         self.content_navigation_components('navcontentbottom')
    65         self.content_navigation_components('navcontentbottom')
    58 
    66 
    59     ...
    67     ...
    60 
    68 
    61 ``cell_call`` is executed for each entity of a result set and apply ``render_entity``.
    69 ``cell_call`` is executed for each entity of a result set.
    62 
    70 
    63 The methods you want to modify while customizing a ``PrimaryView`` are:
    71 The methods you want to modify while customizing a ``PrimaryView`` are:
    64 
    72 
    65 *render_entity_title(self, entity)*
    73 *render_entity_title(self, entity)*
    66     Renders the entity title based on the assumption that the method
    74     Renders the entity title based on the assumption that the method
    67     ``def content_title(self)`` is implemented for the given entity type.
    75     ``def dc_title(self)`` is implemented for the given entity type.
    68 
    76 
    69 *render_entity_metadata(self, entity)*
    77 *render_entity_metadata(self, entity)*
    70     Renders the entity metadata based on the assumption that the method
    78     Renders the entity metadata by calling the 'metadata' view on the
    71     ``def summary(self)`` is implemented for the given entity type.
    79     entity. This generic view is in cubicweb.views.baseviews.
    72 
    80 
    73 *render_entity_attributes(self, entity, siderelations)*
    81 *render_entity_attributes(self, entity)*
    74     Renders all the attribute of an entity with the exception of attribute
    82     Renders all the attribute of an entity with the exception of
    75     of type `Password` and `Bytes`.
    83     attribute of type `Password` and `Bytes`. The skip_none class
       
    84     attribute controls the display of None valued attributes.
    76 
    85 
    77 *content_navigation_components(self, context)*
    86 *content_navigation_components(self, context)*
    78     This method is applicable only for entity type implementing the interface
    87     This method is applicable only for entity type implementing the interface
    79     `IPrevNext`. This interface is for entities which can be linked to a previous
    88     `IPrevNext`. This interface is for entities which can be linked to a previous
    80     and/or next entity. This methods will render the navigation links between
    89     and/or next entity. This methods will render the navigation links between
    81     entities of this type, either at the top or at the bottom of the page
    90     entities of this type, either at the top or at the bottom of the page
    82     given the context (navcontent{top|bottom}).
    91     given the context (navcontent{top|bottom}).
    83 
    92 
    84 *render_entity_relations(self, entity, siderelations)*
    93 *render_entity_relations(self, entity)*
    85     Renders all the relations of the entity in the main section of the page.
    94     Renders all the relations of the entity in the main section of the page.
    86 
    95 
    87 *render_side_related(self, entity, siderelations)*
    96 *render_side_boxes(self, entity, boxes)*
    88     Renders all the relations of the entity in a side box. This is equivalent
    97     Renders all the relations of the entity in a side box. This is equivalent
    89     to *render_entity_relations* in addition to render the relations
    98     to *render_entity_relations* in addition to render the relations
    90     in a box.
    99     in a box.
    91 
   100 
    92 Also, please note that by setting the following attributes in you class,
   101 Also, please note that by setting the following attributes in your class,
    93 you can already customize some of the rendering:
   102 you can already customize some of the rendering:
    94 
   103 
    95 *show_attr_label*
   104 *show_attr_label*
    96     Renders the attribute label next to the attribute value if set to True.
   105     Renders the attribute label next to the attribute value if set to True.
    97     Otherwise, does only display the attribute value.
   106     Otherwise, does only display the attribute value.