doc/book/en/development/webstdlib/primary.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 02 Mar 2010 19:15:26 +0100
branchstable
changeset 4751 1a9d2c3c7f0c
parent 4437 21f2e01fdd6a
child 4936 a4b772a0d801
permissions -rw-r--r--
[book] more id -> __regid__
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
The default 'primary' view (:mod:`cubicweb.web.views.primary`)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
---------------------------------------------------------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
The primary view of an entity is the view called by default when a single
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
     5
entity is in the result set and needs to be displayed.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
This view is supposed to render a maximum of informations about the entity.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
4430
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
     9
Beware when overriding this top level `cell_call` in a primary because
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
    10
you will loose a bunch of functionnality that automatically comes with
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
    11
it : `in-context` boxes, related boxes, some navigation, some
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
    12
displaying of the metadata, etc. It might be interresting to
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
    13
understand the implementation fo the `cell_call` to override specifics
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
    14
bits of it.
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3258
diff changeset
    15
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
Rendering methods and attributes for ``PrimaryView``
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
----------------------------------------------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    19
By default, *CubicWeb* provides a primary view for every available
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    20
entity type. This is the first view you might be interested in
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    21
modifying.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
Let's have a quick look at the EntityView ``PrimaryView`` as well as
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
its rendering method
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
2545
f8246ed962f6 [doc] replace code-block with sourcecode
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    26
.. sourcecode:: python
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    27
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
    class PrimaryView(EntityView):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
        """the full view of an non final entity"""
4751
1a9d2c3c7f0c [book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4437
diff changeset
    30
        __regid__ = 'primary'
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
        title = _('primary')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
        show_attr_label = True
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
        show_rel_label = True
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
        skip_none = True
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    35
        rsection = uicfg.primaryview_section
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    36
        display_ctrl = uicfg.primaryview_display_ctrl
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
        main_related_section = True
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
        ...
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
    def cell_call(self, row, col):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
        self.row = row
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4430
diff changeset
    43
        self.maxrelated = self._cw.property_value('navigation.related-limit')
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    44
        entity = self.complete_entity(row, col)
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    45
        self.render_entity(entity)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    46
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
    def render_entity(self, entity):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
        self.render_entity_title(entity)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
        self.render_entity_metadata(entity)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    50
        # entity's attributes and relations, excluding meta data
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
        # if the entity isn't meta itself
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    52
        boxes = self._prepare_side_boxes(entity)
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    53
        if boxes or hasattr(self, 'render_side_related'):
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    54
            self.w(u'<table width="100%"><tr><td style="width: 75%">')
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    55
        self.render_entity_summary(entity)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
        self.w(u'<div class="mainInfo">')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
        self.content_navigation_components('navcontenttop')
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    58
        self.render_entity_attributes(entity)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
        if self.main_related_section:
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    60
            self.render_entity_relations(entity)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
        self.w(u'</div>')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
        # side boxes
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    63
        if boxes or hasattr(self, 'render_side_related'):
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    64
            self.w(u'</td><td>')
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    65
            self.w(u'<div class="primaryRight">')
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    66
            if hasattr(self, 'render_side_related'):
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    67
                warn('render_side_related is deprecated')
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    68
                self.render_side_related(entity, [])
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    69
            self.render_side_boxes(boxes)
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    70
            self.w(u'</div>')
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    71
            self.w(u'</td></tr></table>')
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
        self.content_navigation_components('navcontentbottom')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
    ...
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    76
``cell_call`` is executed for each entity of a result set.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
The methods you want to modify while customizing a ``PrimaryView`` are:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    80
*render_entity_title(self, entity)*
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    81
    Renders the entity title based on the assumption that the method
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    82
    ``def dc_title(self)`` is implemented for the given entity type.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
*render_entity_metadata(self, entity)*
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    85
    Renders the entity metadata by calling the 'metadata' view on the
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    86
    entity. This generic view is in cubicweb.views.baseviews.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    88
*render_entity_attributes(self, entity)*
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    89
    Renders all the attribute of an entity with the exception of
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    90
    attribute of type `Password` and `Bytes`. The skip_none class
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
    91
    attribute controls the display of None valued attributes.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    92
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    93
*content_navigation_components(self, context)*
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    94
    This method is applicable only for entity type implementing the interface
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    95
    `IPrevNext`. This interface is for entities which can be linked to a previous
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
    and/or next entity. This methods will render the navigation links between
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
    entities of this type, either at the top or at the bottom of the page
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
    given the context (navcontent{top|bottom}).
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    99
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   100
*render_entity_relations(self, entity)*
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   101
    Renders all the relations of the entity in the main section of the page.
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   102
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   103
*render_side_boxes(self, entity, boxes)*
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   104
    Renders all the relations of the entity in a side box. This is equivalent
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   105
    to *render_entity_relations* in addition to render the relations
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
    in a box.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   107
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   108
Also, please note that by setting the following attributes in your class,
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   109
you can already customize some of the rendering:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   110
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   111
*show_attr_label*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   112
    Renders the attribute label next to the attribute value if set to True.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   113
    Otherwise, does only display the attribute value.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   114
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   115
*show_rel_label*
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   116
    Renders the relation label next to the relation value if set to True.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   117
    Otherwise, does only display the relation value.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   118
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   119
*skip_none*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
    Does not render an attribute value that is None if set to True.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   122
*main_related_section*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
    Renders the relations of the entity if set to True.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   124
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
A good practice is for you to identify the content of your entity type for which
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   126
the default rendering does not answer your need so that you can focus on the specific
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
method (from the list above) that needs to be modified. We do not recommand you to
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   128
overwrite ``render_entity`` as you might potentially loose the benefits of the side
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
boxes handling.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   130
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   131
.. XXX talk about uicfg.rdisplay