author | Julien Cristau <julien.cristau@logilab.fr> |
Mon, 21 Dec 2015 15:44:20 +0100 | |
changeset 11010 | 09be4709c8c0 |
parent 10495 | 5bd914ebf3ae |
permissions | -rw-r--r-- |
5266
84f285d96363
[doc/book] regroup views chapters under common umbrella (in the development part) & some fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5262
diff
changeset
|
1 |
.. _primary_view: |
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4751
diff
changeset
|
2 |
|
5227
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
3 |
The Primary View |
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
4 |
----------------- |
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
5 |
|
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
6 |
By default, *CubicWeb* provides a view that fits every available |
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
7 |
entity type. This is the first view you might be interested in |
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
8 |
modifying. It is also one of the richest and most complex. |
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
9 |
|
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
10 |
It is automatically selected on a one line result set containing an |
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
11 |
entity. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
|
5400
b7ab099b128a
[doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5394
diff
changeset
|
13 |
It lives in the :mod:`cubicweb.web.views.primary` module. |
b7ab099b128a
[doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5394
diff
changeset
|
14 |
|
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
15 |
The *primary* view is supposed to render a maximum of informations about the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
16 |
entity. |
5227
ed1c138299f2
[doc/book] primary view section enhancements
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5222
diff
changeset
|
17 |
|
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
18 |
.. _primary_view_layout: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
19 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
20 |
Layout |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
21 |
`````` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
22 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
23 |
The primary view has the following layout. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
24 |
|
10495
5bd914ebf3ae
[doc] fix warnings/errors in doc build
Julien Cristau <julien.cristau@logilab.fr>
parents:
10491
diff
changeset
|
25 |
.. image:: ../../../images/primaryview_template.png |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
26 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
27 |
.. _primary_view_configuration: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
28 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
29 |
Primary view configuration |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
30 |
`````````````````````````` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
31 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
32 |
If you want to customize the primary view of an entity, overriding the primary |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
33 |
view class may not be necessary. For simple adjustments (attributes or relations |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
34 |
display locations and styles), a much simpler way is to use uicfg. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
35 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
36 |
Attributes/relations display location |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
37 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
38 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
39 |
In the primary view, there are three sections where attributes and |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
40 |
relations can be displayed (represented in pink in the image above): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
41 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
42 |
* 'attributes' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
43 |
* 'relations' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
44 |
* 'sideboxes' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
45 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
46 |
**Attributes** can only be displayed in the attributes section (default |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
47 |
behavior). They can also be hidden. By default, attributes of type `Password` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
48 |
and `Bytes` are hidden. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
49 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
50 |
For instance, to hide the ``title`` attribute of the ``Blog`` entity: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
51 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
52 |
.. sourcecode:: python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
53 |
|
8665
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8190
diff
changeset
|
54 |
from cubicweb.web.views import uicfg |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
55 |
uicfg.primaryview_section.tag_attribute(('Blog', 'title'), 'hidden') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
56 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
57 |
**Relations** can be either displayed in one of the three sections or hidden. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
58 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
59 |
For relations, there are two methods: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
60 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
61 |
* ``tag_object_of`` for modifying the primary view of the object |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
62 |
* ``tag_subject_of`` for modifying the primary view of the subject |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
63 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
64 |
These two methods take two arguments: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
65 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
66 |
* a triplet ``(subject, relation_name, object)``, where subject or object can be replaced with ``'*'`` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
67 |
* the section name or ``hidden`` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
68 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
69 |
.. sourcecode:: python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
70 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
71 |
pv_section = uicfg.primaryview_section |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
72 |
# hide every relation `entry_of` in the `Blog` primary view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
73 |
pv_section.tag_object_of(('*', 'entry_of', 'Blog'), 'hidden') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
74 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
75 |
# display `entry_of` relations in the `relations` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
76 |
# section in the `BlogEntry` primary view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
77 |
pv_section.tag_subject_of(('BlogEntry', 'entry_of', '*'), 'relations') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
78 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
79 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
80 |
Display content |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
81 |
^^^^^^^^^^^^^^^ |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
82 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
83 |
You can use ``primaryview_display_ctrl`` to customize the display of attributes |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
84 |
or relations. Values of ``primaryview_display_ctrl`` are dictionaries. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
85 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
86 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
87 |
Common keys for attributes and relations are: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
88 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
89 |
* ``vid``: specifies the regid of the view for displaying the attribute or the relation. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
90 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
91 |
If ``vid`` is not specified, the default value depends on the section: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
92 |
* ``attributes`` section: 'reledit' view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
93 |
* ``relations`` section: 'autolimited' view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
94 |
* ``sideboxes`` section: 'sidebox' view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
95 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
96 |
* ``order``: int used to control order within a section. When not specified, |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
97 |
automatically set according to order in which tags are added. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
98 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
99 |
* ``label``: label for the relations section or side box |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
100 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
101 |
* ``showlabel``: boolean telling whether the label is displayed |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
102 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
103 |
.. sourcecode:: python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
104 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
105 |
# let us remind the schema of a blog entry |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
106 |
class BlogEntry(EntityType): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
107 |
title = String(required=True, fulltextindexed=True, maxsize=256) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
108 |
publish_date = Date(default='TODAY') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
109 |
content = String(required=True, fulltextindexed=True) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
110 |
entry_of = SubjectRelation('Blog', cardinality='?*') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
111 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
112 |
# now, we want to show attributes |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
113 |
# with an order different from that in the schema definition |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
114 |
view_ctrl = uicfg.primaryview_display_ctrl |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
115 |
for index, attr in enumerate('title', 'content', 'publish_date'): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
116 |
view_ctrl.tag_attribute(('BlogEntry', attr), {'order': index}) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
117 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
118 |
By default, relations displayed in the 'relations' section are being displayed by |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
119 |
the 'autolimited' view. This view will use comma separated values, or list view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
120 |
and/or limit your rset if there is too much items in it (and generate the "view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
121 |
all" link in this case). |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
122 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
123 |
You can control this view by setting the following values in the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
124 |
`primaryview_display_ctrl` relation tag: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
125 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
126 |
* `limit`, maximum number of entities to display. The value of the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
127 |
'navigation.related-limit' cwproperty is used by default (which is 8 by default). |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
128 |
If None, no limit. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
129 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
130 |
* `use_list_limit`, number of entities until which they should be display as a list |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
131 |
(eg using the 'list' view). Below that limit, the 'csv' view is used. If None, |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
132 |
display using 'csv' anyway. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
133 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
134 |
* `subvid`, the subview identifier (eg view that should be used of each item in the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
135 |
list) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
136 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
137 |
Notice you can also use the `filter` key to set up a callback taking the related |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
138 |
result set as argument and returning it filtered, to do some arbitrary filtering |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
139 |
that can't be done using rql for instance. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
140 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
141 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
142 |
.. sourcecode:: python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
143 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
144 |
pv_section = uicfg.primaryview_section |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
145 |
# in `CWUser` primary view, display `created_by` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
146 |
# relations in relations section |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
147 |
pv_section.tag_object_of(('*', 'created_by', 'CWUser'), 'relations') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
148 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
149 |
# display this relation as a list, sets the label, |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
150 |
# limit the number of results and filters on comments |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
151 |
def filter_comment(rset): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
152 |
return rset.filtered_rset(lambda x: x.e_schema == 'Comment') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
153 |
pv_ctrl = uicfg.primaryview_display_ctrl |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
154 |
pv_ctrl.tag_object_of(('*', 'created_by', 'CWUser'), |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
155 |
{'vid': 'list', 'label': _('latest comment(s):'), |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
156 |
'limit': True, |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
157 |
'filter': filter_comment}) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
158 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
159 |
.. warning:: with the ``primaryview_display_ctrl`` rtag, the subject or the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
160 |
object of the relation is ignored for respectively ``tag_object_of`` or |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
161 |
``tag_subject_of``. To avoid warnings during execution, they should be set to |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
162 |
``'*'``. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
163 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
164 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
165 |
.. automodule:: cubicweb.web.views.primary |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
166 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
167 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
168 |
Example of customization and creation |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
169 |
````````````````````````````````````` |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
170 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
171 |
We'll show you now an example of a ``primary`` view and how to customize it. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
172 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
173 |
If you want to change the way a ``BlogEntry`` is displayed, just |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
174 |
override the method ``cell_call()`` of the view ``primary`` in |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
175 |
``BlogDemo/views.py``. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
176 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
177 |
.. sourcecode:: python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
178 |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8032
diff
changeset
|
179 |
from cubicweb.predicates import is_instance |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
180 |
from cubicweb.web.views.primary import Primaryview |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
181 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
182 |
class BlogEntryPrimaryView(PrimaryView): |
8032
bcb87336c7d2
[doc] fix most of ReST compilation errors and warnings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7844
diff
changeset
|
183 |
__select__ = PrimaryView.__select__ & is_instance('BlogEntry') |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
184 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
185 |
def render_entity_attributes(self, entity): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
186 |
self.w(u'<p>published on %s</p>' % |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
187 |
entity.publish_date.strftime('%Y-%m-%d')) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
188 |
super(BlogEntryPrimaryView, self).render_entity_attributes(entity) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
189 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
190 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
191 |
The above source code defines a new primary view for |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
192 |
``BlogEntry``. The `__reid__` class attribute is not repeated there since it |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
193 |
is inherited through the `primary.PrimaryView` class. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
194 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
195 |
The selector for this view chains the selector of the inherited class |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
196 |
with its own specific criterion. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
197 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
198 |
The view method ``self.w()`` is used to output data. Here `lines |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
199 |
08-09` output HTML for the publication date of the entry. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
200 |
|
10495
5bd914ebf3ae
[doc] fix warnings/errors in doc build
Julien Cristau <julien.cristau@logilab.fr>
parents:
10491
diff
changeset
|
201 |
.. image:: ../../../images/lax-book_09-new-view-blogentry_en.png |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
202 |
:alt: blog entries now look much nicer |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
203 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
204 |
Let us now improve the primary view of a blog |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
205 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
206 |
.. sourcecode:: python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
207 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
208 |
from logilab.mtconverter import xml_escape |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8032
diff
changeset
|
209 |
from cubicweb.predicates import is_instance, one_line_rset |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
210 |
from cubicweb.web.views.primary import Primaryview |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
211 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
212 |
class BlogPrimaryView(PrimaryView): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
213 |
__regid__ = 'primary' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
214 |
__select__ = PrimaryView.__select__ & is_instance('Blog') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
215 |
rql = 'Any BE ORDERBY D DESC WHERE BE entry_of B, BE publish_date D, B eid %(b)s' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
216 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
217 |
def render_entity_relations(self, entity): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
218 |
rset = self._cw.execute(self.rql, {'b' : entity.eid}) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
219 |
for entry in rset.entities(): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
220 |
self.w(u'<p>%s</p>' % entry.view('inblogcontext')) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
221 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
222 |
class BlogEntryInBlogView(EntityView): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
223 |
__regid__ = 'inblogcontext' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
224 |
__select__ = is_instance('BlogEntry') |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
225 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
226 |
def cell_call(self, row, col): |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
227 |
entity = self.cw_rset.get_entity(row, col) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
228 |
self.w(u'<a href="%s" title="%s">%s</a>' % |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
229 |
entity.absolute_url(), |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
230 |
xml_escape(entity.content[:50]), |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
231 |
xml_escape(entity.description)) |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
232 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
233 |
This happens in two places. First we override the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
234 |
render_entity_relations method of a Blog's primary view. Here we want |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
235 |
to display our blog entries in a custom way. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
236 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
237 |
At `line 10`, a simple request is made to build a result set with all |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
238 |
the entities linked to the current ``Blog`` entity by the relationship |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
239 |
``entry_of``. The part of the framework handling the request knows |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
240 |
about the schema and infers that such entities have to be of the |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
241 |
``BlogEntry`` kind and retrieves them (in the prescribed publish_date |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
242 |
order). |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
243 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
244 |
The request returns a selection of data called a result set. Result |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
245 |
set objects have an .entities() method returning a generator on |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
246 |
requested entities (going transparently through the `ORM` layer). |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
247 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
248 |
At `line 13` the view 'inblogcontext' is applied to each blog entry to |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
249 |
output HTML. (Note that the 'inblogcontext' view is not defined |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
250 |
whatsoever in *CubicWeb*. You are absolutely free to define whole view |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
251 |
families.) We juste arrange to wrap each blogentry output in a 'p' |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
252 |
html element. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
253 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
254 |
Next, we define the 'inblogcontext' view. This is NOT a primary view, |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
255 |
with its well-defined sections (title, metadata, attribtues, |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
256 |
relations/boxes). All a basic view has to define is cell_call. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
257 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
258 |
Since views are applied to result sets which can be tables of data, we |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
259 |
have to recover the entity from its (row,col)-coordinates (`line |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
260 |
20`). Then we can spit some HTML. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
261 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
262 |
.. warning:: |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
263 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
264 |
Be careful: all strings manipulated in *CubicWeb* are actually |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
265 |
unicode strings. While web browsers are usually tolerant to |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
266 |
incoherent encodings they are being served, we should not abuse |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
267 |
it. Hence we have to properly escape our data. The xml_escape() |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
268 |
function has to be used to safely fill (X)HTML elements from Python |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
269 |
unicode strings. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
270 |
|
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
271 |
Assuming we added entries to the blog titled `MyLife`, displaying it |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
272 |
now allows to read its description and all its entries. |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
273 |
|
10495
5bd914ebf3ae
[doc] fix warnings/errors in doc build
Julien Cristau <julien.cristau@logilab.fr>
parents:
10491
diff
changeset
|
274 |
.. image:: ../../../images/lax-book_10-blog-with-two-entries_en.png |
7844
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
275 |
:alt: a blog and all its entries |
0208c65a88a5
[doc] split API/book part of stuff that has been moved in primary view module docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7838
diff
changeset
|
276 |