author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Tue, 30 Dec 2008 11:47:25 +0100 | |
changeset 309 | 7067c97cb182 |
parent 308 | 73a352526577 |
child 316 | 99943acb44af |
permissions | -rw-r--r-- |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
1 |
.. -*- coding: utf-8 -*- |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
2 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
3 |
.. _DefinitionVues: |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
4 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
5 |
Views definition |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
6 |
================ |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
7 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
8 |
This chapter aims to describe the concept of a `view` used all along |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
9 |
the development of a web application and how it has been implemented |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
10 |
in `CubicWeb`. |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
11 |
|
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
12 |
We'll start with a description of the interface providing you with a basic |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
13 |
understanding of the classes and methods available, then detail the view |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
14 |
selection principle we makes is makes `CubicWeb` web interface very flexible. |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
15 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
16 |
Basic class for views |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
17 |
--------------------- |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
18 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
19 |
Class `View` (`cubicweb.common.view`) |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
20 |
````````````````````````````````````` |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
21 |
|
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
22 |
This class is an abstraction of a view class, used as a base class for every |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
23 |
renderable object such as views, templates, graphic components, etc. |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
24 |
|
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
25 |
A `View` is instantiated to render a result set or part of a result set. `View` |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
26 |
subclasses may be parametrized using the following class attributes: |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
27 |
|
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
28 |
* `templatable` indicates if the view may be embeded in a main |
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
29 |
template or if it has to be rendered standalone (i.e. XML views |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
30 |
must not be embeded in the main template for HTML pages) |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
31 |
* if the view is not templatable, it should set the `content_type` class |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
32 |
attribute to the correct MIME type (text/xhtml by default) |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
33 |
* the `category` attribute may be used in the interface to regroup related |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
34 |
objects together |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
35 |
|
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
36 |
At instantiation time, the standard `req`, `rset`, and `cursor` |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
37 |
attributes are added and the `w` attribute will be set at rendering |
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
38 |
time. |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
39 |
|
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
40 |
A view writes to its output stream thanks to its attribute `w` (`UStreamIO`). |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
41 |
|
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
42 |
The basic interface for views is as follows (remember that the result set has a |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
43 |
tabular structure with rows and columns, hence cells): |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
44 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
45 |
* `dispatch(**context)`, render the view by calling `call` or |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
46 |
`cell_call` depending on the given parameters |
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
47 |
* `call(**kwargs)`, call the view for a complete result set or null (default |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
48 |
implementation calls `cell_call()` on each cell of the result set) |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
49 |
* `cell_call(row, col, **kwargs)`, call the view for a given cell of a result set |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
50 |
* `url()`, returns the URL enabling us to get the view with the current |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
51 |
result set |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
52 |
* `view(__vid, rset, __fallback_vid=None, **kwargs)`, call the view of identifier |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
53 |
`__vid` on the given result set. It is possible to give a view identifier |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
54 |
of fallback that will be used if the view requested is not applicable to the |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
55 |
result set |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
56 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
57 |
* `wview(__vid, rset, __fallback_vid=None, **kwargs)`, similar to `view` except |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
58 |
the flow is automatically passed in the parameters |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
59 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
60 |
* `html_headers()`, returns a list of HTML headers to set by the main template |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
61 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
62 |
* `page_title()`, returns the title to use in the HTML header `title` |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
63 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
64 |
* `creator(eid)`, returns the eid and the login of the entity creator of the entity |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
65 |
having the eid given in the parameter |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
66 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
67 |
Other basic views classes |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
68 |
````````````````````````` |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
69 |
Here are some of the subclasses of `View` defined in `cubicweb.common.view` |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
70 |
that are more concrete as they relates to data rendering within the application: |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
71 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
72 |
* `EntityView`, view applying to lines or cell containing an entity (e.g. an eid) |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
73 |
* `StartupView`, start view that does not require a result set to apply to |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
74 |
* `AnyRsetView`, view applied to any result set |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
75 |
* `EmptyRsetView`, view applied to an empty result set |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
76 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
77 |
The selection view principle |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
78 |
---------------------------- |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
79 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
80 |
A view includes : |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
81 |
|
306
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
82 |
- an identifier (all objects in `CubicWeb` are entered in a registry |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
83 |
and this identifier will be used as a key). This is defined in the class |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
84 |
attribute ``id``. |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
85 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
86 |
- a filter to select the resulsets it can be applied to. This is defined in |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
87 |
the class attribute ``__selectors__`` |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
88 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
89 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
90 |
For a given identifier, multiple views can be defined. `CubicWeb` uses |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
91 |
a selector which computes scores so that it can identify and select the |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
92 |
best view to apply in context. The selector library is in |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
93 |
``cubicweb.common.selector`` and a library of the methods used to |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
94 |
compute scores is in ``cubicweb.vregistry.vreq``. |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
95 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
96 |
|
306
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
97 |
`CubicWeb` provides a lot of standard views for the default class |
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
98 |
`EntityType`. You can find them in ``cubicweb/web/views/``. |
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
99 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
100 |
.. include:: B1021-views-stdlib.en.txt |
306
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
101 |
|
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
102 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
103 |
Example of a view customization |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
104 |
------------------------------- |
306
1ed1da008e50
[doc] Removes references to LAX.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
301
diff
changeset
|
105 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
106 |
We'll show you now an example of a ``primary`` view and how to customize it. |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
107 |
|
309
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
108 |
If you want to change the way a ``BlogEntry`` is displayed, just override |
7067c97cb182
[doc] minor text improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
308
diff
changeset
|
109 |
the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py`` :: |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
110 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
111 |
01. from ginco.web.views import baseviews |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
112 |
02. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
113 |
03. class BlogEntryPrimaryView(baseviews.PrimaryView): |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
114 |
04. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
115 |
05. accepts = ('BlogEntry',) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
116 |
06. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
117 |
07. def cell_call(self, row, col): |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
118 |
08. entity = self.entity(row, col) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
119 |
09. self.w(u'<h1>%s</h1>' % entity.title) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
120 |
10. self.w(u'<p>published on %s in category %s</p>' % \ |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
121 |
11. (entity.publish_date.strftime('%Y-%m-%d'), entity.category)) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
122 |
12. self.w(u'<p>%s</p>' % entity.text) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
123 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
124 |
The above source code defines a new primary view (`line 03`) for |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
125 |
``BlogEntry`` (`line 05`). |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
126 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
127 |
Since views are applied to resultsets and resulsets can be tables of |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
128 |
data, it is needed to recover the entity from its (row,col) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
129 |
coordinates (`line 08`). We will get to this in more detail later. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
130 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
131 |
The view has a ``self.w()`` method that is used to output data. Here `lines |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
132 |
09-12` output HTML tags and values of the entity's attributes. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
133 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
134 |
When displaying same blog entry as before, you will notice that the |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
135 |
page is now looking much nicer. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
136 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
137 |
.. image:: images/lax-book.09-new-view-blogentry.en.png |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
138 |
:alt: blog entries now look much nicer |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
139 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
140 |
Let us now improve the primary view of a blog :: |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
141 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
142 |
01. class BlogPrimaryView(baseviews.PrimaryView): |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
143 |
02. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
144 |
03. accepts = ('Blog',) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
145 |
04. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
146 |
05. def cell_call(self, row, col): |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
147 |
06. entity = self.entity(row, col) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
148 |
07. self.w(u'<h1>%s</h1>' % entity.title) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
149 |
08. self.w(u'<p>%s</p>' % entity.description) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
150 |
09. rset = self.req.execute('Any E WHERE E entry_of B, B eid "%s"' % entity.eid) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
151 |
10. self.wview('primary', rset) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
152 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
153 |
In the above source code, `lines 01-08` are similar to the previous |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
154 |
view we defined. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
155 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
156 |
At `line 09`, a simple request in made to build a resultset with all |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
157 |
the entities linked to the current ``Blog`` entity by the relationship |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
158 |
``entry_of``. The part of the framework handling the request knows |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
159 |
about the schema and infer that such entities have to be of the |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
160 |
``BlogEntry`` kind and retrieves them. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
161 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
162 |
The request returns a selection of data called a resultset. At |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
163 |
`line 10` the view 'primary' is applied to this resultset to output |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
164 |
HTML. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
165 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
166 |
**This is to be compared to interfaces and protocols in object-oriented |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
167 |
languages. Applying a given view to all the entities of a resultset only |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
168 |
requires the availability, for each entity of this resultset, of a |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
169 |
view with that name that can accepts the entity.** |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
170 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
171 |
Assuming we added entries to the blog titled `MyLife`, displaying it |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
172 |
now allows to read its description and all its entries. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
173 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
174 |
.. image:: images/lax-book.10-blog-with-two-entries.en.png |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
175 |
:alt: a blog and all its entries |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
176 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
177 |
**Before we move forward, remember that the selection/view principle is |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
178 |
at the core of `CubicWeb`. Everywhere in the engine, data is requested |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
179 |
using the RQL language, then HTML/XML/text/PNG is output by applying a |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
180 |
view to the resultset returned by the query. That is where most of the |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
181 |
flexibility comes from.** |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
182 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
183 |
[WRITE ME] |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
184 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
185 |
* implementing interfaces, calendar for blog entries |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
186 |
* show that a calendar view can export data to ical |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
187 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
188 |
We will implement the `cubicweb.interfaces.ICalendarable` interfaces on |
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
189 |
entities.BlogEntry and apply the OneMonthCalendar and iCalendar views |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
190 |
to resultsets like "Any E WHERE E is BlogEntry" |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
191 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
192 |
* create view "blogentry table" with title, publish_date, category |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
193 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
194 |
We will show that by default the view that displays |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
195 |
"Any E,D,C WHERE E publish_date D, E category C" is the table view. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
196 |
Of course, the same can be obtained by calling |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
197 |
self.wview('table',rset) |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
198 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
199 |
* in view blog, select blogentries and apply view "blogentry table" |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
200 |
* demo ajax by filtering blogentry table on category |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
201 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
202 |
we did the same with 'primary', but with tables we can turn on filters |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
203 |
and show that ajax comes for free. |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
204 |
[FILLME] |
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
205 |
|
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
206 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
207 |
Templates |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
208 |
--------- |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
209 |
|
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
210 |
*Templates* are specific view that does not depend on a result set. The basic |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
211 |
class `Template` (`cubicweb.common.view`) is derived from the class `View`. |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
212 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
213 |
To build a HTML page, a *main template* is used. In general, the template of |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
214 |
identifier `main` is the one to use (it is not used in case an error is raised or for |
229
767ff7f5d5a7
[doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
127
diff
changeset
|
215 |
the login form for example). This template uses other templates in addition |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
216 |
to the views which depends on the content to generate the HTML page to return. |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
217 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
218 |
A *template* is responsible for: |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
219 |
|
301 | 220 |
1. executing RQL query of data to render if necessary |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
221 |
2. identifying the view to use to render data if it is not specified |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
222 |
3. composing the HTML page to return |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
223 |
|
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
224 |
You will find out more about templates in :ref:`templates`. |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
225 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
226 |
XML views, binaries... |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
227 |
---------------------- |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
228 |
For the views generating other formats that HTML (an image generated dynamically |
229
767ff7f5d5a7
[doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
127
diff
changeset
|
229 |
for example), and which can not usually be included in the HTML page generated |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
230 |
by the main template (see above), you have to: |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
231 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
232 |
* set the atribute `templatable` of the class to `False` |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
233 |
* set, through the attribute `content_type` of the class, the MIME type generated |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
234 |
by the view to `application/octet-stream` |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
235 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
236 |
For the views dedicated to binary content creation (an image dynamically generated |
229
767ff7f5d5a7
[doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
127
diff
changeset
|
237 |
for example), we have to set the attribute `binary` of the class to `True` (which |
308
73a352526577
[doc] Improvement to the Views chapter. Moved content about the main template in the Templates chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
306
diff
changeset
|
238 |
implies that `templatable == False`, so that the attribute `w` of the view could be |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
239 |
replaced by a binary flow instead of unicode). |
93
9c919a47e140
[doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
240 |
|
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
241 |
(X)HTML tricks to apply |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
242 |
----------------------- |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
243 |
|
229
767ff7f5d5a7
[doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
127
diff
changeset
|
244 |
Some web browser (Firefox for example) are not happy with empty `<div>` |
102
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
245 |
(by empty we mean that there is no content in the tag, but there |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
246 |
could be attributes), so we should always use `<div></div>` even if |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
247 |
it is empty and not use `<div/>`. |
ef84f6b2e4cf
[doc] Initial translation of views chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
93
diff
changeset
|
248 |