doc/book/en/development/webstdlib/primary.rst
branchtls-sprint
changeset 1714 a721966779be
child 2172 cf8f9180e63e
equal deleted inserted replaced
1499:fd8751c3f3ee 1714:a721966779be
       
     1 The default 'primary' view (:mod:`cubicweb.web.views.primary`)
       
     2 ---------------------------------------------------------------
       
     3 
       
     4 The primary view of an entity is the view called by default when a single
       
     5 entity is in the result set and needs to be displayed. 
       
     6 
       
     7 This view is supposed to render a maximum of informations about the entity.
       
     8 
       
     9 
       
    10 
       
    11 Rendering methods and attributes for ``PrimaryView``
       
    12 ----------------------------------------------------
       
    13 
       
    14 By default, `CubicWeb` provides a primary view for each new entity type
       
    15 you create. The first view you might be interested in modifying.
       
    16 
       
    17 Let's have a quick look at the EntityView ``PrimaryView`` as well as
       
    18 its rendering method
       
    19 
       
    20 .. code-block:: python
       
    21     
       
    22     class PrimaryView(EntityView):
       
    23         """the full view of an non final entity"""
       
    24         id = 'primary'
       
    25         title = _('primary')
       
    26         show_attr_label = True
       
    27         show_rel_label = True
       
    28         skip_none = True
       
    29         skip_attrs = ('eid', 'creation_date', 'modification_date')
       
    30         skip_rels = ()
       
    31         main_related_section = True
       
    32 
       
    33         ...
       
    34 
       
    35     def cell_call(self, row, col):
       
    36         self.row = row
       
    37         self.render_entity(self.complete_entity(row, col))
       
    38 
       
    39     def render_entity(self, entity):
       
    40         """return html to display the given entity"""
       
    41         siderelations = []
       
    42         self.render_entity_title(entity)
       
    43         self.render_entity_metadata(entity)
       
    44         # entity's attributes and relations, excluding meta data
       
    45         # if the entity isn't meta itself
       
    46         self.w(u'<div>')
       
    47         self.w(u'<div class="mainInfo">')
       
    48         self.render_entity_attributes(entity, siderelations)
       
    49         self.w(u'</div>')
       
    50         self.content_navigation_components('navcontenttop')
       
    51         if self.main_related_section:
       
    52             self.render_entity_relations(entity, siderelations)
       
    53         self.w(u'</div>')
       
    54         # side boxes
       
    55         self.w(u'<div class="primaryRight">')
       
    56         self.render_side_related(entity, siderelations)
       
    57         self.w(u'</div>')
       
    58         self.w(u'<div class="clear"></div>')
       
    59         self.content_navigation_components('navcontentbottom')
       
    60 
       
    61     ...
       
    62 
       
    63 ``cell_call`` is executed for each entity of a result set and apply ``render_entity``.
       
    64 
       
    65 The methods you want to modify while customizing a ``PrimaryView`` are:
       
    66 
       
    67 *render_entity_title(self, entity)* 
       
    68     Renders the entity title based on the assumption that the method 
       
    69     ``def content_title(self)`` is implemented for the given entity type.
       
    70 
       
    71 *render_entity_metadata(self, entity)*
       
    72     Renders the entity metadata based on the assumption that the method
       
    73     ``def summary(self)`` is implemented for the given entity type.
       
    74 
       
    75 *render_entity_attributes(self, entity, siderelations)*
       
    76     Renders all the attribute of an entity with the exception of attribute
       
    77     of type `Password` and `Bytes`.
       
    78 
       
    79 *content_navigation_components(self, context)*
       
    80     This method is applicable only for entity type implementing the interface 
       
    81     `IPrevNext`. This interface is for entities which can be linked to a previous
       
    82     and/or next entity. This methods will render the navigation links between
       
    83     entities of this type, either at the top or at the bottom of the page
       
    84     given the context (navcontent{top|bottom}).
       
    85 
       
    86 *render_entity_relations(self, entity, siderelations)*
       
    87     Renders all the relations of the entity in the main section of the page.
       
    88         
       
    89 *render_side_related(self, entity, siderelations)*
       
    90     Renders all the relations of the entity in a side box. This is equivalent
       
    91     to *render_entity_relations* in addition to render the relations
       
    92     in a box.
       
    93 
       
    94 Also, please note that by setting the following attributes in you class,
       
    95 you can already customize some of the rendering:
       
    96 
       
    97 *show_attr_label*
       
    98     Renders the attribute label next to the attribute value if set to True.
       
    99     Otherwise, does only display the attribute value.
       
   100 
       
   101 *show_rel_label* 
       
   102     Renders the relation label next to the relation value if set to True.
       
   103     Otherwise, does only display the relation value.
       
   104 
       
   105 *skip_none*
       
   106     Does not render an attribute value that is None if set to True.
       
   107 
       
   108 *main_related_section*
       
   109     Renders the relations of the entity if set to True.
       
   110 
       
   111 A good practice is for you to identify the content of your entity type for which
       
   112 the default rendering does not answer your need so that you can focus on the specific
       
   113 method (from the list above) that needs to be modified. We do not recommand you to
       
   114 overwrite ``render_entity`` as you might potentially loose the benefits of the side
       
   115 boxes handling.
       
   116 
       
   117 .. XXX talk about uicfg.rdisplay