web/views/primary.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 22 Sep 2011 19:13:58 +0200
branchstable
changeset 7838 ea1360938033
parent 7837 6f32f142e2da
child 7844 0208c65a88a5
permissions -rw-r--r--
[doc] backport primary view documentation into the code, also document [URL]AttributeView
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7837
6f32f142e2da [primary sub views] use entity_call instead of cell_call
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    18
"""
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    19
The *primary* view is supposed to render a maximum of informations about the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    20
entity.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    21
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    22
.. _primary_view_layout:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    23
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    24
Layout
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    25
``````
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    26
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    27
The primary view has the following layout.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    28
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    29
.. image:: ../../images/primaryview_template.png
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    30
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    31
.. _primary_view_configuration:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    32
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    33
Primary view configuration
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    34
``````````````````````````
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    35
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    36
If you want to customize the primary view of an entity, overriding the primary
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    37
view class may not be necessary. For simple adjustments (attributes or relations
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    38
display locations and styles), a much simpler way is to use uicfg.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    39
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    40
Attributes/relations display location
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    41
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    42
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    43
In the primary view, there are three sections where attributes and
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    44
relations can be displayed (represented in pink in the image above):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    45
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    46
* 'attributes'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    47
* 'relations'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    48
* 'sideboxes'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    49
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    50
**Attributes** can only be displayed in the attributes section (default
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    51
  behavior). They can also be hidden. By default, attributes of type `Password`
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    52
  and `Bytes` are hidden.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    53
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    54
For instance, to hide the ``title`` attribute of the ``Blog`` entity:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    55
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    56
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    57
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    58
   from cubicweb.web import uicfg
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    59
   uicfg.primaryview_section.tag_attribute(('Blog', 'title'), 'hidden')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    60
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    61
**Relations** can be either displayed in one of the three sections or hidden.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    62
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    63
For relations, there are two methods:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    64
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    65
* ``tag_object_of`` for modifying the primary view of the object
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    66
* ``tag_subject_of`` for modifying the primary view of the subject
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    67
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    68
These two methods take two arguments:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    69
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    70
* a triplet ``(subject, relation_name, object)``, where subject or object can be replaced with ``'*'``
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    71
* the section name or ``hidden``
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    72
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    73
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    74
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    75
   pv_section = uicfg.primaryview_section
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    76
   # hide every relation `entry_of` in the `Blog` primary view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    77
   pv_section.tag_object_of(('*', 'entry_of', 'Blog'), 'hidden')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    78
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    79
   # display `entry_of` relations in the `relations`
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    80
   # section in the `BlogEntry` primary view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    81
   pv_section.tag_subject_of(('BlogEntry', 'entry_of', '*'), 'relations')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    82
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    83
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    84
Display content
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    85
^^^^^^^^^^^^^^^
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    86
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    87
You can use ``primaryview_display_ctrl`` to customize the display of attributes
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    88
or relations. Values of ``primaryview_display_ctrl`` are dictionaries.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    89
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    90
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    91
Common keys for attributes and relations are:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    92
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    93
* ``vid``: specifies the regid of the view for displaying the attribute or the relation.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    94
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    95
  If ``vid`` is not specified, the default value depends on the section:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    96
    * ``attributes`` section: 'reledit' view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    97
    * ``relations`` section: 'autolimited' view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    98
    * ``sideboxes`` section: 'sidebox' view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
    99
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   100
* ``order``: int used to control order within a section. When not specified,
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   101
  automatically set according to order in which tags are added.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   102
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   103
* ``label``: label for the relations section or side box
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   104
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   105
* ``showlabel``: boolean telling whether the label is displayed
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   106
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   107
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   108
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   109
   # let us remind the schema of a blog entry
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   110
   class BlogEntry(EntityType):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   111
       title = String(required=True, fulltextindexed=True, maxsize=256)
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   112
       publish_date = Date(default='TODAY')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   113
       content = String(required=True, fulltextindexed=True)
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   114
       entry_of = SubjectRelation('Blog', cardinality='?*')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   115
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   116
   # now, we want to show attributes
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   117
   # with an order different from that in the schema definition
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   118
   view_ctrl = uicfg.primaryview_display_ctrl
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   119
   for index, attr in enumerate('title', 'content', 'publish_date'):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   120
       view_ctrl.tag_attribute(('BlogEntry', attr), {'order': index})
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   121
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   122
By default, relations displayed in the 'relations' section are being displayed by
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   123
the 'autolimited' view. This view will use comma separated values, or list view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   124
and/or limit your rset if there is too much items in it (and generate the "view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   125
all" link in this case).
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   126
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   127
You can control this view by setting the following values in the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   128
`primaryview_display_ctrl` relation tag:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   129
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   130
* `limit`, maximum number of entities to display. The value of the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   131
  'navigation.related-limit'  cwproperty is used by default (which is 8 by default).
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   132
  If None, no limit.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   133
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   134
* `use_list_limit`, number of entities until which they should be display as a list
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   135
  (eg using the 'list' view). Below that limit, the 'csv' view is used. If None,
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   136
  display using 'csv' anyway.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   137
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   138
* `subvid`, the subview identifier (eg view that should be used of each item in the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   139
  list)
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   140
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   141
Notice you can also use the `filter` key to set up a callback taking the related
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   142
result set as argument and returning it filtered, to do some arbitrary filtering
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   143
that can't be done using rql for instance.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   144
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   145
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   146
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   147
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   148
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   149
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   150
   pv_section = uicfg.primaryview_section
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   151
   # in `CWUser` primary view, display `created_by`
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   152
   # relations in relations section
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   153
   pv_section.tag_object_of(('*', 'created_by', 'CWUser'), 'relations')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   154
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   155
   # display this relation as a list, sets the label,
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   156
   # limit the number of results and filters on comments
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   157
   def filter_comment(rset):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   158
       return rset.filtered_rset(lambda x: x.e_schema == 'Comment')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   159
   pv_ctrl = uicfg.primaryview_display_ctrl
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   160
   pv_ctrl.tag_object_of(('*', 'created_by', 'CWUser'),
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   161
                         {'vid': 'list', 'label': _('latest comment(s):'),
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   162
                          'limit': True,
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   163
                          'filter': filter_comment})
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   164
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   165
.. warning:: with the ``primaryview_display_ctrl`` rtag, the subject or the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   166
   object of the relation is ignored for respectively ``tag_object_of`` or
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   167
   ``tag_subject_of``. To avoid warnings during execution, they should be set to
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   168
   ``'*'``.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   169
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   170
Rendering methods and attributes
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   171
````````````````````````````````
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   172
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   173
The basic layout of a primary view is as in the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   174
:ref:`primary_view_layout` section. This layout is actually drawn by
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   175
the `render_entity` method.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   176
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   177
The methods you may want to modify while customizing a ``PrimaryView``
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   178
are:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   179
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   180
*render_entity_title(self, entity)*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   181
    Renders the entity title, by default using entity's :meth:`dc_title()` method.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   182
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   183
*render_entity_attributes(self, entity)*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   184
    Renders all attributes and relations in the 'attributes' section . The
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   185
    :attr:`skip_none` attribute controls the display of `None` valued attributes.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   186
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   187
*render_entity_relations(self, entity)*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   188
    Renders all relations in the 'relations' section.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   189
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   190
*render_side_boxes(self, entity, boxes)*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   191
    Renders side boxes on the right side of the content. This will generate a box
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   192
    for each relation in the 'sidebox' section, as well as explicit box
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   193
    appobjects selectable in this context.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   194
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   195
The placement of relations in the relations section or in side boxes
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   196
can be controlled through the :ref:`primary_view_configuration` mechanism.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   197
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   198
*content_navigation_components(self, context)*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   199
    This method is applicable only for entity type implementing the interface
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   200
    `IPrevNext`. This interface is for entities which can be linked to a previous
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   201
    and/or next entity. This method will render the navigation links between
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   202
    entities of this type, either at the top or at the bottom of the page
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   203
    given the context (navcontent{top|bottom}).
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   204
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   205
Also, please note that by setting the following attributes in your
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   206
subclass, you can already customize some of the rendering:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   207
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   208
*show_attr_label*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   209
    Renders the attribute label next to the attribute value if set to `True`.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   210
    Otherwise, does only display the attribute value.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   211
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   212
*show_rel_label*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   213
    Renders the relation label next to the relation value if set to `True`.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   214
    Otherwise, does only display the relation value.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   215
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   216
*skip_none*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   217
    Does not render an attribute value that is None if set to `True`.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   218
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   219
*main_related_section*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   220
    Renders the relations of the entity if set to `True`.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   221
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   222
A good practice is for you to identify the content of your entity type for which
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   223
the default rendering does not answer your need so that you can focus on the specific
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   224
method (from the list above) that needs to be modified. We do not advise you to
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   225
overwrite ``render_entity`` unless you want a completely different layout.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   226
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   227
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   228
Example of customization and creation
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   229
`````````````````````````````````````
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   230
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   231
We'll show you now an example of a ``primary`` view and how to customize it.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   232
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   233
If you want to change the way a ``BlogEntry`` is displayed, just
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   234
override the method ``cell_call()`` of the view ``primary`` in
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   235
``BlogDemo/views.py``.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   236
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   237
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   238
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   239
   from cubicweb.selectors import is_instance
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   240
   from cubicweb.web.views.primary import Primaryview
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   241
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   242
   class BlogEntryPrimaryView(PrimaryView):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   243
     __select__ = PrimaryView.__select__ & is_instance('BlogEntry')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   244
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   245
       def render_entity_attributes(self, entity):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   246
           self.w(u'<p>published on %s</p>' %
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   247
                  entity.publish_date.strftime('%Y-%m-%d'))
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   248
           super(BlogEntryPrimaryView, self).render_entity_attributes(entity)
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   249
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   250
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   251
The above source code defines a new primary view for
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   252
``BlogEntry``. The `__reid__` class attribute is not repeated there since it
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   253
is inherited through the `primary.PrimaryView` class.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   254
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   255
The selector for this view chains the selector of the inherited class
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   256
with its own specific criterion.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   257
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   258
The view method ``self.w()`` is used to output data. Here `lines
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   259
08-09` output HTML for the publication date of the entry.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   260
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   261
.. image:: ../../images/lax-book_09-new-view-blogentry_en.png
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   262
   :alt: blog entries now look much nicer
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   263
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   264
Let us now improve the primary view of a blog
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   265
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   266
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   267
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   268
 from logilab.mtconverter import xml_escape
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   269
 from cubicweb.selectors import is_instance, one_line_rset
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   270
 from cubicweb.web.views.primary import Primaryview
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   271
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   272
 class BlogPrimaryView(PrimaryView):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   273
     __regid__ = 'primary'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   274
     __select__ = PrimaryView.__select__ & is_instance('Blog')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   275
     rql = 'Any BE ORDERBY D DESC WHERE BE entry_of B, BE publish_date D, B eid %(b)s'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   276
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   277
     def render_entity_relations(self, entity):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   278
         rset = self._cw.execute(self.rql, {'b' : entity.eid})
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   279
         for entry in rset.entities():
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   280
             self.w(u'<p>%s</p>' % entry.view('inblogcontext'))
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   281
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   282
 class BlogEntryInBlogView(EntityView):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   283
     __regid__ = 'inblogcontext'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   284
     __select__ = is_instance('BlogEntry')
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   285
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   286
     def cell_call(self, row, col):
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   287
         entity = self.cw_rset.get_entity(row, col)
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   288
         self.w(u'<a href="%s" title="%s">%s</a>' %
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   289
                entity.absolute_url(),
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   290
                xml_escape(entity.content[:50]),
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   291
                xml_escape(entity.description))
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   292
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   293
This happens in two places. First we override the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   294
render_entity_relations method of a Blog's primary view. Here we want
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   295
to display our blog entries in a custom way.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   296
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   297
At `line 10`, a simple request is made to build a result set with all
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   298
the entities linked to the current ``Blog`` entity by the relationship
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   299
``entry_of``. The part of the framework handling the request knows
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   300
about the schema and infers that such entities have to be of the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   301
``BlogEntry`` kind and retrieves them (in the prescribed publish_date
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   302
order).
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   303
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   304
The request returns a selection of data called a result set. Result
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   305
set objects have an .entities() method returning a generator on
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   306
requested entities (going transparently through the `ORM` layer).
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   307
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   308
At `line 13` the view 'inblogcontext' is applied to each blog entry to
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   309
output HTML. (Note that the 'inblogcontext' view is not defined
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   310
whatsoever in *CubicWeb*. You are absolutely free to define whole view
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   311
families.) We juste arrange to wrap each blogentry output in a 'p'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   312
html element.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   313
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   314
Next, we define the 'inblogcontext' view. This is NOT a primary view,
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   315
with its well-defined sections (title, metadata, attribtues,
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   316
relations/boxes). All a basic view has to define is cell_call.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   317
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   318
Since views are applied to result sets which can be tables of data, we
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   319
have to recover the entity from its (row,col)-coordinates (`line
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   320
20`). Then we can spit some HTML.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   321
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   322
.. warning::
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   323
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   324
  Be careful: all strings manipulated in *CubicWeb* are actually
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   325
  unicode strings. While web browsers are usually tolerant to
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   326
  incoherent encodings they are being served, we should not abuse
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   327
  it. Hence we have to properly escape our data. The xml_escape()
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   328
  function has to be used to safely fill (X)HTML elements from Python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   329
  unicode strings.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   330
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   331
Assuming we added entries to the blog titled `MyLife`, displaying it
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   332
now allows to read its description and all its entries.
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   333
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   334
.. image:: ../../images/lax-book_10-blog-with-two-entries_en.png
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   335
   :alt: a blog and all its entries
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   336
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   337
Views that may be used to display an entity's attribute or relation
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   338
```````````````````````````````````````````````````````````````````
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   339
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   340
Yoy may easily the display of an attribute or relation by simply configuring the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   341
view using one of `primaryview_display_ctrl` or `reledit_ctrl` to use one of the
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   342
views describled below. For instance:
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   343
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   344
.. sourcecode:: python
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   345
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   346
    primaryview_display_ctrl.tag_attribute(('Foo', 'bar'), {'vid': 'attribute'})
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   347
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   348
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   349
.. autoclass:: AttributeView
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   350
.. autoclass:: URLAttributeView
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   351
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   352
"""
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   353
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   354
__docformat__ = "restructuredtext en"
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   355
_ = unicode
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   356
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   357
from warnings import warn
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   358
6634
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   359
from logilab.common.deprecation import deprecated
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2237
diff changeset
   360
from logilab.mtconverter import xml_escape
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   361
6235
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   362
from cubicweb import Unauthorized, NoSelectableObject
6067
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   363
from cubicweb.utils import support_args
6446
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   364
from cubicweb.selectors import match_kwargs, match_context
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   365
from cubicweb.view import EntityView
6377
3bb415310d4f [schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6371
diff changeset
   366
from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name
6446
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   367
from cubicweb.web import uicfg, component
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   368
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   369
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   370
class PrimaryView(EntityView):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   371
    """the full view of an non final entity"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3072
diff changeset
   372
    __regid__ = 'primary'
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   373
    title = _('primary')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   374
    show_attr_label = True
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   375
    show_rel_label = True
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   376
    skip_none = True
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   377
    rsection = uicfg.primaryview_section
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   378
    display_ctrl = uicfg.primaryview_display_ctrl
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   379
    main_related_section = True
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   380
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   381
    def html_headers(self):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   382
        """return a list of html headers (eg something to be inserted between
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   383
        <head> and </head> of the returned page
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   384
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   385
        by default primary views are indexed
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   386
        """
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   387
        return []
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   388
6847
c1d33aff7715 [primary view] support for entity_call on primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6634
diff changeset
   389
    def entity_call(self, entity):
c1d33aff7715 [primary view] support for entity_call on primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6634
diff changeset
   390
        entity.complete()
2400
17b1f0b80fe8 [primary] restore render_entity, as it is a bit too much work to update everything accordingly
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2384
diff changeset
   391
        self.render_entity(entity)
17b1f0b80fe8 [primary] restore render_entity, as it is a bit too much work to update everything accordingly
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2384
diff changeset
   392
17b1f0b80fe8 [primary] restore render_entity, as it is a bit too much work to update everything accordingly
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2384
diff changeset
   393
    def render_entity(self, entity):
4566
c49dba55c0a6 [views] toolbox must be rendered before the title to appear at top right
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 4467
diff changeset
   394
        self.render_entity_toolbox(entity)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   395
        self.render_entity_title(entity)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   396
        # entity's attributes and relations, excluding meta data
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   397
        # if the entity isn't meta itself
3974
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   398
        if self.is_primary():
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   399
            boxes = self._prepare_side_boxes(entity)
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   400
        else:
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   401
            boxes = None
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   402
        if boxes or hasattr(self, 'render_side_related'):
1558
f63d090eb34a some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   403
            self.w(u'<table width="100%"><tr><td style="width: 75%">')
6634
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   404
        if hasattr(self, 'render_entity_summary'):
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   405
            warn('[3.10] render_entity_summary method is deprecated (%s)' % self,
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   406
                 DeprecationWarning)
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   407
            self.render_entity_summary(entity)
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   408
        summary = self.summary(entity)
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   409
        if summary:
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   410
            warn('[3.10] summary method is deprecated (%s)' % self,
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   411
                 DeprecationWarning)
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   412
            self.w(u'<div class="summary">%s</div>' % summary)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   413
        self.w(u'<div class="mainInfo">')
2132
d7ae060cd746 move navcontenttop on the top
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1977
diff changeset
   414
        self.content_navigation_components('navcontenttop')
2384
6220783caa4b [primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2381
diff changeset
   415
        self.render_entity_attributes(entity)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   416
        if self.main_related_section:
2384
6220783caa4b [primary] cleanup, render_entity -> cell_call
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2381
diff changeset
   417
            self.render_entity_relations(entity)
4742
fac80328a6a3 [primary] navcontentbottom sections should be in the content table as navcontenttop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4572
diff changeset
   418
        self.content_navigation_components('navcontentbottom')
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   419
        self.w(u'</div>')
2237
7e546c3d6ea5 [primary] fix #344249
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2217
diff changeset
   420
        # side boxes
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   421
        if boxes or hasattr(self, 'render_side_related'):
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   422
            self.w(u'</td><td>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   423
            self.w(u'<div class="primaryRight">')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   424
            if hasattr(self, 'render_side_related'):
5614
37b31a7b8e74 [primary] add missing version number to deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5560
diff changeset
   425
                warn('[3.2] render_side_related is deprecated')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   426
                self.render_side_related(entity, [])
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   427
            self.render_side_boxes(boxes)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   428
            self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   429
            self.w(u'</td></tr></table>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   430
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   431
    def content_navigation_components(self, context):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   432
        self.w(u'<div class="%s">' % context)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   433
        for comp in self._cw.vreg['ctxcomponents'].poss_visible_objects(
6500
e288df2e2f18 [component] remove row argument which is actually discarded by registry's cache (untill we feel we need a per context cache...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6476
diff changeset
   434
            self._cw, rset=self.cw_rset, view=self, context=context):
6926
2cda8f1b4fae cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6634
diff changeset
   435
            # XXX bw compat code
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   436
            try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   437
                comp.render(w=self.w, row=self.cw_row, view=self)
6616
26587186b856 [primary view bw compat] we should actually drop 3.2 compat and have proper pre 3.10 compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   438
            except TypeError:
26587186b856 [primary view bw compat] we should actually drop 3.2 compat and have proper pre 3.10 compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   439
                comp.render(w=self.w)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   440
        self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   441
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   442
    def render_entity_title(self, entity):
1720
14c9a0a1aca1 drop content_title
sylvain.thenault@logilab.fr
parents: 1632
diff changeset
   443
        """default implementation return dc_title"""
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2237
diff changeset
   444
        title = xml_escape(entity.dc_title())
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   445
        if title:
3974
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   446
            if self.is_primary():
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   447
                self.w(u'<h1>%s</h1>' % title)
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   448
            else:
4104
7e478d7caf20 [mq]: small_api_changes_for_3.6
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 4074
diff changeset
   449
                atitle = self._cw._('follow this link for more information on this %s') % entity.dc_type()
3974
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   450
                self.w(u'<h4><a href="%s" title="%s">%s</a></h4>'
1d36d9904c41 slightly adapt title and hide boxes when view is called as a non primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3972
diff changeset
   451
                       % (entity.absolute_url(), atitle, title))
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   452
3845
596044fb7bc5 introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3844
diff changeset
   453
    def render_entity_toolbox(self, entity):
596044fb7bc5 introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3844
diff changeset
   454
        self.content_navigation_components('ctxtoolbar')
596044fb7bc5 introduce render_entity_toolbox on default primary view to display components in the ctxtoolbar context, such as pdf icon, notification registration (nosylist)...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3844
diff changeset
   455
6634
0683748bca81 [primary view] properly deprecates render_entity_[summary|metadata]
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6616
diff changeset
   456
    @deprecated('[3.8] render_entity_metadata method is deprecated')
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   457
    def render_entity_metadata(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   458
        entity.view('metadata', w=self.w)
3064
3fbcdf220ce9 fix so that entity's summary appears in main content cell to avoid layout pb
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2655
diff changeset
   459
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   460
    def summary(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   461
        """default implementation return an empty string"""
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   462
        return u''
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   463
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
   464
    def render_entity_attributes(self, entity):
5180
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   465
        display_attributes = []
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   466
        for rschema, _, role, dispctrl in self._section_def(entity, 'attributes'):
2361
8f00836580f1 [reledit] do NOT propose to edit composite-related entities (unlinking would destroy the other side)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2312
diff changeset
   467
            vid = dispctrl.get('vid', 'reledit')
6070
0ca78eb1a3c2 [primary] use a new rtypevid flag in primary view display controller, allowing to tell the view for a non final relation should be called as an attribute view (eg, not on the target rset)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   468
            if rschema.final or vid == 'reledit' or dispctrl.get('rtypevid'):
6086
2b53a8669c98 [primary] handle final relation (eg attribute) in the relations section, and give dispctrl to view's extra kwargs as for non final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6070
diff changeset
   469
                value = entity.view(vid, rtype=rschema.type, role=role,
2b53a8669c98 [primary] handle final relation (eg attribute) in the relations section, and give dispctrl to view's extra kwargs as for non final relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6070
diff changeset
   470
                                    initargs={'dispctrl': dispctrl})
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   471
            else:
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   472
                rset = self._relation_rset(entity, rschema, role, dispctrl)
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   473
                if rset:
4382
6fb02edd05da 3.6 api update, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   474
                    value = self._cw.view(vid, rset)
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   475
                else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   476
                    value = None
5180
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   477
            if not self.skip_none or (value is not None and value != ''):
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   478
                display_attributes.append( (rschema, role, dispctrl, value) )
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   479
        if display_attributes:
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   480
            self.w(u'<table>')
5182
3bc8250731fe [primary] fix name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5180
diff changeset
   481
            for rschema, role, dispctrl, value in display_attributes:
6371
9af007a3acb9 fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6366
diff changeset
   482
                if not hasattr(self, '_render_attribute'):
6067
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   483
                    label = self._rel_label(entity, rschema, role, dispctrl)
6366
1806148d6ce8 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333 6335
diff changeset
   484
                    self.render_attribute(label, value, table=True)
6067
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   485
                elif support_args(self._render_attribute, 'dispctrl'):
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   486
                    warn('[3.9] _render_attribute prototype has changed and '
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   487
                         'renamed to render_attribute, please update %s'
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   488
                         % self.__class___, DeprecationWarning)
6067
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   489
                    self._render_attribute(dispctrl, rschema, value, role=role,
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   490
                                           table=True)
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   491
                else:
5180
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   492
                    self._render_attribute(rschema, value, role=role, table=True)
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   493
                    warn('[3.6] _render_attribute prototype has changed and '
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   494
                         'renamed to render_attribute, please update %s'
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   495
                         % self.__class___, DeprecationWarning)
5180
25c3269b2232 [xthml] fix #696079, potential empty table cause xhtml validation error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5065
diff changeset
   496
            self.w(u'</table>')
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   497
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   498
    def render_attribute(self, label, value, table=False):
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   499
        self.field(label, value, tr=False, table=table)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   500
5239
471554b842d2 [schema view] the final touch. Things are getting nicely displayed, and code clean
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5222
diff changeset
   501
    def render_entity_relations(self, entity):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   502
        for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'):
6113
dbe17a3ebb9f [primary view] consider rtypevid flag for relations in the 'relations' section as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6093
diff changeset
   503
            if rschema.final or dispctrl.get('rtypevid'):
6235
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   504
                vid = dispctrl.get('vid', 'reledit')
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   505
                try:
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   506
                    rview = self._cw.vreg['views'].select(
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   507
                        vid, self._cw, rset=entity.cw_rset, row=entity.cw_row,
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   508
                        col=entity.cw_col, dispctrl=dispctrl,
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   509
                        rtype=rschema, role=role)
6235
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   510
                except NoSelectableObject:
d5f7bd102282 [primary view] properly handle case where view specified in pvdc['vid'] isn't selectable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6234
diff changeset
   511
                    continue
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   512
                value = rview.render(row=entity.cw_row, col=entity.cw_col,
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   513
                                     rtype=rschema.type, role=role)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   514
            else:
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   515
                rset = self._relation_rset(entity, rschema, role, dispctrl)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   516
                if not rset:
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   517
                    continue
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   518
                if hasattr(self, '_render_relation'):
6366
1806148d6ce8 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333 6335
diff changeset
   519
                    if not support_args(self._render_relation, 'showlabel'):
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   520
                        self._render_relation(dispctrl, rset, 'autolimited')
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   521
                        warn('[3.9] _render_relation prototype has changed and has '
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   522
                             'been renamed to render_relation, please update %s'
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   523
                             % self.__class__, DeprecationWarning)
6366
1806148d6ce8 backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333 6335
diff changeset
   524
                    else:
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   525
                        self._render_relation(rset, dispctrl, 'autolimited',
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   526
                                              self.show_rel_label)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   527
                        warn('[3.6] _render_relation prototype has changed and has '
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   528
                             'been renamed to render_relation, please update %s'
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   529
                             % self.__class__, DeprecationWarning)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   530
                    continue
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   531
                vid = dispctrl.get('vid', 'autolimited')
3970
e4ad7663610b update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3875
diff changeset
   532
                try:
6335
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   533
                    rview = self._cw.vreg['views'].select(
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   534
                        vid, self._cw, rset=rset, dispctrl=dispctrl)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   535
                except NoSelectableObject:
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   536
                    continue
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   537
                value = rview.render()
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   538
            label = self._rel_label(entity, rschema, role, dispctrl)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   539
            self.render_relation(label, value)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   540
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   541
    def render_relation(self, label, value):
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   542
        self.w(u'<div class="section">')
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   543
        if label:
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   544
            self.w(u'<h4>%s</h4>' % label)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   545
        self.w(value)
d13d488a453e [primary view] refactor label handling (hence render_[attribute|relation]) so we uniformly use _rel_label which provides properly contextified labels
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6291
diff changeset
   546
        self.w(u'</div>')
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   547
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   548
    def render_side_boxes(self, boxes):
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   549
        """display side related relations:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   550
        non-meta in a first step, meta in a second step
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   551
        """
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   552
        for box in boxes:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   553
            if isinstance(box, tuple):
3975
569771016abb add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3974
diff changeset
   554
                try:
569771016abb add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3974
diff changeset
   555
                    label, rset, vid, dispctrl  = box
569771016abb add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3974
diff changeset
   556
                except ValueError:
5560
b9a8e7109370 [primary view] fix name error on dispctrl w/ pre 3.5 box definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5520
diff changeset
   557
                    label, rset, vid = box
b9a8e7109370 [primary view] fix name error on dispctrl w/ pre 3.5 box definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5520
diff changeset
   558
                    dispctrl = {}
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   559
                warn('[3.10] box views should now be a RsetBox instance, '
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   560
                     'please update %s' % self.__class__.__name__,
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   561
                     DeprecationWarning)
1885
c2011d238e98 replace sideRelated with sideBox
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1752
diff changeset
   562
                self.w(u'<div class="sideBox">')
5519
bdc6a7e724f3 [primary view] give dispctrl to side box views as for relations section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   563
                self.wview(vid, rset, title=label, initargs={'dispctrl': dispctrl})
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   564
                self.w(u'</div>')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   565
            else:
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   566
                 try:
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   567
                     box.render(w=self.w, row=self.cw_row)
6616
26587186b856 [primary view bw compat] we should actually drop 3.2 compat and have proper pre 3.10 compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   568
                 except TypeError:
26587186b856 [primary view bw compat] we should actually drop 3.2 compat and have proper pre 3.10 compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6582
diff changeset
   569
                     box.render(w=self.w)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   570
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   571
    def _prepare_side_boxes(self, entity):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   572
        sideboxes = []
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   573
        boxesreg = self._cw.vreg['ctxcomponents']
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   574
        for rschema, tschemas, role, dispctrl in self._section_def(entity, 'sideboxes'):
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   575
            rset = self._relation_rset(entity, rschema, role, dispctrl)
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   576
            if not rset:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   577
                continue
6067
efca814587e2 [primary] refactor primary view handling of relation's label
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5896
diff changeset
   578
            label = self._rel_label(entity, rschema, role, dispctrl)
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   579
            vid = dispctrl.get('vid', 'autolimited')
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   580
            box = boxesreg.select('rsetbox', self._cw, rset=rset,
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   581
                                  vid=vid, title=label, dispctrl=dispctrl,
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   582
                                  context='incontext')
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   583
            sideboxes.append(box)
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   584
        sideboxes += boxesreg.poss_visible_objects(
6500
e288df2e2f18 [component] remove row argument which is actually discarded by registry's cache (untill we feel we need a per context cache...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6476
diff changeset
   585
             self._cw, rset=self.cw_rset, view=self,
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   586
             context='incontext')
3975
569771016abb add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3974
diff changeset
   587
        # XXX since we've two sorted list, it may be worth using bisect
569771016abb add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3974
diff changeset
   588
        def get_order(x):
6140
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   589
            if 'order' in x.cw_property_defs:
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   590
                return x.cw_propval('order')
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   591
            # default to 9999 so view boxes occurs after component boxes
65a619eb31c4 [boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6139
diff changeset
   592
            return x.cw_extra_kwargs.get('dispctrl', {}).get('order', 9999)
3975
569771016abb add a fourth item to 'view box' defintion, dispctrl, so that
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3974
diff changeset
   593
        return sorted(sideboxes, key=get_order)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   594
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   595
    def _section_def(self, entity, where):
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   596
        rdefs = []
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   597
        eschema = entity.e_schema
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   598
        for rschema, tschemas, role in eschema.relation_definitions(True):
5065
01d85f3a3d9e [primary view] skip virtual rtypes anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4742
diff changeset
   599
            if rschema in VIRTUAL_RTYPES:
01d85f3a3d9e [primary view] skip virtual rtypes anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4742
diff changeset
   600
                continue
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   601
            matchtschemas = []
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   602
            for tschema in tschemas:
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   603
                section = self.rsection.etype_get(eschema, rschema, role,
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   604
                                                  tschema)
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   605
                if section == where:
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   606
                    matchtschemas.append(tschema)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   607
            if matchtschemas:
6234
ae97a8c818e5 [primary view] don't need to pick arbitrary target, this is properly handled by the rtag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6113
diff changeset
   608
                dispctrl = self.display_ctrl.etype_get(eschema, rschema, role, '*')
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   609
                rdefs.append( (rschema, matchtschemas, role, dispctrl) )
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   610
        return sorted(rdefs, key=lambda x: x[-1]['order'])
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   611
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   612
    def _relation_rset(self, entity, rschema, role, dispctrl):
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   613
        try:
6291
f6cba3be6ba2 [primary view] we should not limit related rset, else if something else than autolimited view is used, some content will be missed without a 'view all' link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6290
diff changeset
   614
            rset = entity.related(rschema.type, role)
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   615
        except Unauthorized:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   616
            return
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   617
        if 'filter' in dispctrl:
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   618
            rset = dispctrl['filter'](rset)
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   619
        return rset
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   620
6090
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   621
    def _rel_label(self, entity, rschema, role, dispctrl):
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   622
        if rschema.final:
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   623
            showlabel = dispctrl.get('showlabel', self.show_attr_label)
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   624
        else:
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   625
            showlabel = dispctrl.get('showlabel', self.show_rel_label)
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   626
        if showlabel:
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   627
            if dispctrl.get('label'):
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   628
                label = self._cw._(dispctrl['label'])
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   629
            else:
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   630
                label = display_name(self._cw, rschema.type, role,
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   631
                                     context=entity.__regid__)
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   632
            return label
887c069d88df [primary] backport _rel_label method from the default branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6086
diff changeset
   633
        return u''
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   634
6093
9001a74fcc82 more generic dot graph generator
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 6090
diff changeset
   635
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   636
class RelatedView(EntityView):
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6255
diff changeset
   637
    """Display a rset, usually containing entities linked to another entity
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6255
diff changeset
   638
    being displayed.
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6255
diff changeset
   639
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6255
diff changeset
   640
    It will try to display nicely according to the number of items in the result
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6255
diff changeset
   641
    set.
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   642
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   643
    XXX include me in the doc
6283
c827fa795a6b [reledit] more api cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6255
diff changeset
   644
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3072
diff changeset
   645
    __regid__ = 'autolimited'
3681
cdbe4aac1198 fix max-related of related entities handling in primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3071
diff changeset
   646
3705
5cd35123866b get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   647
    def call(self, **kwargs):
4072
ead446e70c28 some api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4004
diff changeset
   648
        if 'dispctrl' in self.cw_extra_kwargs:
6291
f6cba3be6ba2 [primary view] we should not limit related rset, else if something else than autolimited view is used, some content will be missed without a 'view all' link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6290
diff changeset
   649
            if 'limit' in self.cw_extra_kwargs['dispctrl']:
f6cba3be6ba2 [primary view] we should not limit related rset, else if something else than autolimited view is used, some content will be missed without a 'view all' link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6290
diff changeset
   650
                limit = self.cw_extra_kwargs['dispctrl']['limit']
f6cba3be6ba2 [primary view] we should not limit related rset, else if something else than autolimited view is used, some content will be missed without a 'view all' link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6290
diff changeset
   651
            else:
f6cba3be6ba2 [primary view] we should not limit related rset, else if something else than autolimited view is used, some content will be missed without a 'view all' link
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6290
diff changeset
   652
                limit = self._cw.property_value('navigation.related-limit')
6288
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   653
            list_limit = self.cw_extra_kwargs['dispctrl'].get('use_list_limit', 5)
5520
2d7f135846ee [primary view] allow new 'subvid' parameter in primaryview_display_ctrl
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5519
diff changeset
   654
            subvid = self.cw_extra_kwargs['dispctrl'].get('subvid', 'incontext')
3705
5cd35123866b get dispctrl through extra_kwargs to avoid error when a custom view is specified (potentially not taking any argument)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   655
        else:
6288
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   656
            limit = list_limit = None
5520
2d7f135846ee [primary view] allow new 'subvid' parameter in primaryview_display_ctrl
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5519
diff changeset
   657
            subvid = 'incontext'
3720
5376aaadd16b backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451 3705
diff changeset
   658
        if limit is None or self.cw_rset.rowcount <= limit:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   659
            if self.cw_rset.rowcount == 1:
5520
2d7f135846ee [primary view] allow new 'subvid' parameter in primaryview_display_ctrl
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5519
diff changeset
   660
                self.wview(subvid, self.cw_rset, row=0)
6288
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   661
            elif list_limit is None or 1 < self.cw_rset.rowcount <= list_limit:
5520
2d7f135846ee [primary view] allow new 'subvid' parameter in primaryview_display_ctrl
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5519
diff changeset
   662
                self.wview('csv', self.cw_rset, subvid=subvid)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   663
            else:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   664
                self.w(u'<div>')
5520
2d7f135846ee [primary view] allow new 'subvid' parameter in primaryview_display_ctrl
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5519
diff changeset
   665
                self.wview('simplelist', self.cw_rset, subvid=subvid)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   666
                self.w(u'</div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   667
        # else show links to display related entities
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   668
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
   669
            rql = self.cw_rset.printable_rql()
6476
de7f53cf75ec [primary] fix autolimited view which was not limited at all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6446
diff changeset
   670
            rset = self.cw_rset.limit(limit) # remove extra entity
6288
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   671
            if list_limit is None:
6476
de7f53cf75ec [primary] fix autolimited view which was not limited at all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6446
diff changeset
   672
                self.wview('csv', rset, subvid=subvid)
6288
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   673
                self.w(u'[<a href="%s">%s</a>]' % (
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   674
                    xml_escape(self._cw.build_url(rql=rql, vid=subvid)),
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   675
                    self._cw._('see them all')))
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   676
            else:
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   677
                self.w(u'<div>')
6476
de7f53cf75ec [primary] fix autolimited view which was not limited at all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6446
diff changeset
   678
                self.wview('simplelist', rset, subvid=subvid)
6288
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   679
                self.w(u'[<a href="%s">%s</a>]' % (
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   680
                    xml_escape(self._cw.build_url(rql=rql, vid=subvid)),
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   681
                    self._cw._('see them all')))
17cd9ae3d2d5 [primary view] introducing use_list_limit in pvdc fix reledit regression on the way (introducted a few changesets ago)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6283
diff changeset
   682
                self.w(u'</div>')
2652
3753f3a07ca1 [refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2402
diff changeset
   683
3971
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   684
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   685
class URLAttributeView(EntityView):
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   686
    """:__regid__: *urlattr*
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   687
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   688
    This view will wrap an attribute value (hence expect a string) into an '<a>'
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   689
    HTML tag to display a clickable link.
3971
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   690
    """
4004
c52619c738a5 api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3998
diff changeset
   691
    __regid__ = 'urlattr'
3971
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   692
    __select__ = EntityView.__select__ & match_kwargs('rtype')
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   693
7837
6f32f142e2da [primary sub views] use entity_call instead of cell_call
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   694
    def entity_call(self, entity, rtype, **kwargs):
3971
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   695
        url = entity.printable_value(rtype)
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   696
        if url:
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   697
            self.w(u'<a href="%s">%s</a>' % (url, url))
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   698
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   699
class AttributeView(EntityView):
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   700
    """:__regid__: *attribute*
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   701
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   702
    This view is generally used to disable the *reledit* feature. It works on
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   703
    both relations and attributes.
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   704
    """
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   705
    __regid__ = 'attribute'
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   706
    __select__ = EntityView.__select__ & match_kwargs('rtype')
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   707
7837
6f32f142e2da [primary sub views] use entity_call instead of cell_call
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7782
diff changeset
   708
    def entity_call(self, entity, rtype, **kwargs):
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   709
        if self._cw.vreg.schema.rschema(rtype).final:
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   710
            self.w(entity.printable_value(rtype))
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   711
        else:
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   712
            dispctrl = uicfg.primaryview_display_ctrl.etype_get(
6582
8eb7883b4223 [pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6500
diff changeset
   713
                entity.e_schema, rtype, role, '*')
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   714
            rset = entity.related(rtype, role)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   715
            if rset:
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   716
                self.wview('autolimited', rset, initargs={'dispctrl': dispctrl})
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6235
diff changeset
   717
3971
7cfbc35dce7e new generic urlattr view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3970
diff changeset
   718
6446
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   719
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   720
class ToolbarLayout(component.Layout):
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   721
    # XXX include me in the doc
6446
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   722
    __select__ = match_context('ctxtoolbar')
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   723
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   724
    def render(self, w):
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   725
        if self.init_rendering():
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   726
            self.cw_extra_kwargs['view'].render_body(w)
878fcf10cead [contextual components] missing layout for components in the toolbar
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6377
diff changeset
   727
7838
ea1360938033 [doc] backport primary view documentation into the code, also document [URL]AttributeView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7837
diff changeset
   728
2652
3753f3a07ca1 [refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2402
diff changeset
   729
## default primary ui configuration ###########################################
3753f3a07ca1 [refactoring] moved rtags specification in web/views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2402
diff changeset
   730
3875
c2bd7922cdaf use shorter notation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3849
diff changeset
   731
_pvs = uicfg.primaryview_section
6377
3bb415310d4f [schema] introduce some new sets categorizing entity/relation types and benefits from them where possible
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6371
diff changeset
   732
for rtype in META_RTYPES:
3875
c2bd7922cdaf use shorter notation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3849
diff changeset
   733
    _pvs.tag_subject_of(('*', rtype, '*'), 'hidden')
c2bd7922cdaf use shorter notation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3849
diff changeset
   734
    _pvs.tag_object_of(('*', rtype, '*'), 'hidden')
7782
40a49f4350a5 backout 7780:a1d5365fefc1
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7780
diff changeset
   735
_pvs.tag_subject_of(('*', 'require_permission', '*'), 'hidden')
40a49f4350a5 backout 7780:a1d5365fefc1
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7780
diff changeset
   736
_pvs.tag_object_of(('*', 'require_permission', '*'), 'hidden')