equal
deleted
inserted
replaced
|
1 |
|
2 .. _Views: |
|
3 |
1 Views |
4 Views |
2 ----- |
5 ----- |
3 |
6 |
4 This chapter aims to describe the concept of a `view` used all along |
7 This chapter aims to describe the concept of a `view` used all along |
5 the development of a web application and how it has been implemented |
8 the development of a web application and how it has been implemented |
74 Examples of views class |
77 Examples of views class |
75 ----------------------- |
78 ----------------------- |
76 |
79 |
77 - Using `templatable`, `content_type` and HTTP cache configuration |
80 - Using `templatable`, `content_type` and HTTP cache configuration |
78 |
81 |
79 .. code-block:: python |
82 .. sourcecode:: python |
80 |
|
81 |
83 |
82 class RSSView(XMLView): |
84 class RSSView(XMLView): |
83 id = 'rss' |
85 id = 'rss' |
84 title = _('rss') |
86 title = _('rss') |
85 templatable = False |
87 templatable = False |
86 content_type = 'text/xml' |
88 content_type = 'text/xml' |
87 http_cache_manager = MaxAgeHTTPCacheManager |
89 http_cache_manager = MaxAgeHTTPCacheManager |
88 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
90 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
89 |
91 |
90 |
92 |
91 |
|
92 - Using custom selector |
93 - Using custom selector |
93 |
94 |
94 .. code-block:: python |
95 .. sourcecode:: python |
95 |
|
96 |
96 |
97 class SearchForAssociationView(EntityView): |
97 class SearchForAssociationView(EntityView): |
98 """view called by the edition view when the user asks |
98 """view called by the edition view when the user asks |
99 to search for something to link to the edited eid |
99 to search for something to link to the edited eid |
100 """ |
100 """ |
110 contredicts our advise of not modifying it. |
110 contredicts our advise of not modifying it. |
111 |
111 |
112 We'll show you now an example of a ``primary`` view and how to customize it. |
112 We'll show you now an example of a ``primary`` view and how to customize it. |
113 |
113 |
114 If you want to change the way a ``BlogEntry`` is displayed, just override |
114 If you want to change the way a ``BlogEntry`` is displayed, just override |
115 the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py`` :: |
115 the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py``: |
116 |
116 |
117 .. code-block:: python |
117 .. sourcecode:: python |
118 |
118 |
119 from cubicweb.view import EntityView |
119 from cubicweb.view import EntityView |
120 from cubicweb.selectors import implements |
120 from cubicweb.selectors import implements |
121 |
121 |
122 class BlogEntryPrimaryView(EntityView): |
122 class BlogEntryPrimaryView(EntityView): |
146 .. image:: ../../images/lax-book.09-new-view-blogentry.en.png |
146 .. image:: ../../images/lax-book.09-new-view-blogentry.en.png |
147 :alt: blog entries now look much nicer |
147 :alt: blog entries now look much nicer |
148 |
148 |
149 Let us now improve the primary view of a blog |
149 Let us now improve the primary view of a blog |
150 |
150 |
151 .. code-block:: python |
151 .. sourcecode:: python |
152 |
152 |
153 class BlogPrimaryView(EntityView): |
153 class BlogPrimaryView(EntityView): |
154 id = 'primary' |
154 id = 'primary' |
155 __select__ =implements('Blog') |
155 __select__ =implements('Blog') |
156 |
156 |
213 we did the same with 'primary', but with tables we can turn on filters |
213 we did the same with 'primary', but with tables we can turn on filters |
214 and show that ajax comes for free. |
214 and show that ajax comes for free. |
215 [FILLME] |
215 [FILLME] |
216 |
216 |
217 |
217 |
218 |
|
219 XML views, binaries... |
218 XML views, binaries... |
220 ---------------------- |
219 ---------------------- |
|
220 |
221 For views generating other formats than HTML (an image generated dynamically |
221 For views generating other formats than HTML (an image generated dynamically |
222 for example), and which can not simply be included in the HTML page generated |
222 for example), and which can not simply be included in the HTML page generated |
223 by the main template (see above), you have to: |
223 by the main template (see above), you have to: |
224 |
224 |
225 * set the attribute `templatable` of the class to `False` |
225 * set the attribute `templatable` of the class to `False` |