doc/book/en/devweb/views/baseviews.rst
branchstable
changeset 6303 1aad5389c013
parent 5394 105011657405
child 7836 0ada13ce2e16
equal deleted inserted replaced
6302:ca5d09ff0379 6303:1aad5389c013
     2 
     2 
     3 Base views
     3 Base views
     4 ----------
     4 ----------
     5 
     5 
     6 *CubicWeb* provides a lot of standard views, that can be found in
     6 *CubicWeb* provides a lot of standard views, that can be found in
     7  :mod:`cubicweb.web.views` and :mod:`cubicweb.web.views.baseviews`.
     7 :mod:`cubicweb.web.views` sub-modules.
     8 
     8 
     9 A certain number of views are used to build the web interface, which
     9 A certain number of views are used to build the web interface, which apply to one
    10 apply to one or more entities. Their identifier is what distinguish
    10 or more entities. As other appobject, Their identifier is what distinguish them
    11 them from each others and the main ones are:
    11 from each others. The most generic ones, found in
       
    12 :mod:`cubicweb.web.views.baseviews`, are described below.
    12 
    13 
    13 HTML views
    14 HTML views
    14 ~~~~~~~~~~
    15 ~~~~~~~~~~
    15 
    16 
    16 Special views
    17 Special views
    30 
    31 
    31 *null*
    32 *null*
    32     This view is the default view used when nothing needs to be rendered.
    33     This view is the default view used when nothing needs to be rendered.
    33     It is always applicable.
    34     It is always applicable.
    34 
    35 
       
    36 
    35 Entity views
    37 Entity views
    36 ````````````
    38 ````````````
    37 
    39 
    38 *incontext, outofcontext*
    40 *incontext, outofcontext*
    39     Those are used to display a link to an entity, depending on the
    41 
    40     entity having to be displayed in or out of context
    42     Those are used to display a link to an entity, whose label depends on the
    41     (of another entity).  By default it respectively produces the
    43     entity having to be displayed in or out of context (of another entity): some
    42     result of `textincontext` and `textoutofcontext` wrapped in a link
    44     entities make sense in the context of another entity. For instance, the
    43     leading to the primary view of the entity.
    45     `Version` of a `Project` in forge. So one may expect that 'incontext' will
       
    46     be called when display a version from within the context of a project, while
       
    47     'outofcontext"' will be called in other cases. In our example, the
       
    48     'incontext' view of the version would be something like '0.1.2', while the
       
    49     'outofcontext' view would include the project name, e.g. 'baz 0.1.2' (since
       
    50     only a version number without the associated project doesn't make sense if
       
    51     you don't know yet that you're talking about the famous 'baz' project. |cubicweb|
       
    52     tries to make guess and call 'incontext'/'outofcontext' nicely. When it can't
       
    53     know, the 'oneline' view should be used.
       
    54 
       
    55     By default it respectively produces the result of `textincontext` and
       
    56     `textoutofcontext` wrapped in a link leading to the primary view of the
       
    57     entity.
       
    58 
    44 
    59 
    45 *oneline*
    60 *oneline*
       
    61 
    46     This view is used when we can't tell if the entity should be considered as
    62     This view is used when we can't tell if the entity should be considered as
    47     displayed in or out of context.  By default it produces the result of `text`
    63     displayed in or out of context. By default it produces the result of `text`
    48     in a link leading to the primary view of the entity.
    64     in a link leading to the primary view of the entity.
       
    65 
    49 
    66 
    50 List
    67 List
    51 `````
    68 `````
    52 
    69 
    53 *list*
    70 *list*
    54     This view displays a list of entities by creating a HTML list (`<ul>`)
       
    55     and call the view `listitem` for each entity of the result set.
       
    56 
    71 
    57 *listitem*
    72     This view displays a list of entities by creating a HTML list (`<ul>`) and
    58     This view redirects by default to the `outofcontext` view.
    73     call the view `listitem` for each entity of the result set. The 'list' view
       
    74     will generate html like:
       
    75 
       
    76     .. sourcecode:: html
       
    77 
       
    78       <ul class="section">
       
    79         <li>"result of 'subvid' view for a row</li>
       
    80         ...
       
    81       </ul>
       
    82 
       
    83 
       
    84 *simplelist*
       
    85 
       
    86   This view is not 'ul' based, and rely on div behaviour to separate items. html
       
    87   will look like
       
    88 
       
    89     .. sourcecode:: html
       
    90 
       
    91       <div class="section">"result of 'subvid' view for a row</div>
       
    92       ...
       
    93 
       
    94 
       
    95   It relies on base :class:`~cubicweb.view.View` class implementation of the
       
    96   :meth:`call` method to insert those <div>.
       
    97 
    59 
    98 
    60 *sameetypelist*
    99 *sameetypelist*
    61     This view displays a list of entities of the same type, in HTML section (`<div>`)
       
    62     and call the view `sameetypelistitem` for each entity of the result set.
       
    63 
   100 
    64 *sameetypelistitem*
   101     This view displays a list of entities of the same type, in HTML section
    65     This view redirects by default to the `listitem` view.
   102     (`<div>`) and call the view `sameetypelistitem` for each entity of the result
       
   103     set. It's designed to get a more adapted global list when displayed entities
       
   104     are all of the same type.
       
   105 
    66 
   106 
    67 *csv*
   107 *csv*
    68     This view applies to entity groups, which are individually
   108 
    69     displayed using the `incontext` view. It displays each entity as a
   109     This view displays each entity in a coma separated list. It is NOT related to
    70     coma separated list. It is NOT related to the well-known text file
   110     the well-known text file format.
    71     format.
   111 
       
   112 
       
   113 Those list view can be given a 'subvid' arguments, telling the view to use of
       
   114 each item in the list. When not specified, the value of the 'redirect_vid'
       
   115 attribute of :class:`ListItemView` (for 'listview') or of :class:`SimpleListView`
       
   116 will be used. This default to 'outofcontext' for 'list' / 'incontext' for
       
   117 'simplelist'
       
   118 
    72 
   119 
    73 Text entity views
   120 Text entity views
    74 ~~~~~~~~~~~~~~~~~
   121 ~~~~~~~~~~~~~~~~~
    75 
   122 
       
   123 Basic html view have some variantsto be used when generating raw text, not html
       
   124 (for notifications for instance).
       
   125 
    76 *text*
   126 *text*
       
   127 
    77     This is the simplest text view for an entity. By default it returns the
   128     This is the simplest text view for an entity. By default it returns the
    78     result of the `.dc_title` method, which is cut to fit the
   129     result of the `.dc_title` method, which is cut to fit the
    79     `navigation.short-line-size` property if necessary.
   130     `navigation.short-line-size` property if necessary.
    80 
   131 
    81 *textincontext, textoutofcontext*
   132 *textincontext, textoutofcontext*
    82     Similar to the `text` view, but called when an entity is considered out or
   133 
    83     in context. By default it returns respectively the result of the
   134     Similar to the `text` view, but called when an entity is considered out or in
    84     methods `.dc_title` and `.dc_long_title` of the entity.
   135     context (see description of incontext/outofcontext html views for more
       
   136     information on this). By default it returns respectively the result of the
       
   137     methods `.dc_title()` and `.dc_long_title()` of the entity.