7 |
7 |
8 This chapter aims to describe the concept of a `view` used all along |
8 This chapter aims to describe the concept of a `view` used all along |
9 the development of a web application and how it has been implemented |
9 the development of a web application and how it has been implemented |
10 in `CubicWeb`. |
10 in `CubicWeb`. |
11 |
11 |
12 We'll start with a description of the interface providing you a basic |
12 We'll start with a description of the interface providing you with a basic |
13 understanding of the classes and methods available. We'll also |
13 understanding of the classes and methods available, then detail the view |
14 take time to develop the view selection principle we implemented |
14 selection principle we makes is makes `CubicWeb` web interface very flexible. |
15 which is very unique to `CubicWeb` and makes it powerfull. |
|
16 |
15 |
17 Basic class for views |
16 Basic class for views |
18 --------------------- |
17 --------------------- |
19 |
18 |
20 Class `View` (`cubicweb.common.view`) |
19 Class `View` (`cubicweb.common.view`) |
21 ````````````````````````````````````` |
20 ````````````````````````````````````` |
22 |
21 |
23 This class is an abstraction of a view class, used as a base for every |
22 This class is an abstraction of a view class, used as a base class for every |
24 renderable object such as views, templates, graphic components... web. |
23 renderable object such as views, templates, graphic components, etc. |
25 |
24 |
26 A `View` is instantiated to render a or part of a result set. `View` |
25 A `View` is instantiated to render a result set or part of a result set. `View` |
27 subclasses may be parametrized using the following class attributes: |
26 subclasses may be parametrized using the following class attributes: |
28 |
27 |
29 * `templatable` indicates if the view may be embeded in a main |
28 * `templatable` indicates if the view may be embeded in a main |
30 template or if it has to be rendered standalone (i.e. XML for |
29 template or if it has to be rendered standalone (i.e. XML views |
31 instance) |
30 must not be embeded in the main template for HTML pages) |
32 * if the view is not templatable, it should set the `content_type` class |
31 * if the view is not templatable, it should set the `content_type` class |
33 attribute to the correct MIME type (text/xhtml by default) |
32 attribute to the correct MIME type (text/xhtml by default) |
34 * the `category` attribute may be used in the interface to regroup related |
33 * the `category` attribute may be used in the interface to regroup related |
35 objects together |
34 objects together |
36 |
35 |
37 At instantiation time, the standard `req`, `rset`, and `cursor` |
36 At instantiation time, the standard `req`, `rset`, and `cursor` |
38 attributes are added and the `w` attribute will be set at rendering |
37 attributes are added and the `w` attribute will be set at rendering |
39 time to a write function to use. |
38 time. |
40 |
39 |
41 A view writes in its output exit thanks to its attribute `w` (`UStreamIO`). |
40 A view writes to its output stream thanks to its attribute `w` (`UStreamIO`). |
42 |
41 |
43 The basic interface for views is as follows: |
42 The basic interface for views is as follows (remember that the result set has a |
|
43 tabular structure with rows and columns, hence cells): |
44 |
44 |
45 * `dispatch(**context)`, render the view by calling `call` or |
45 * `dispatch(**context)`, render the view by calling `call` or |
46 `cell_call` depending on the given parameters |
46 `cell_call` depending on the given parameters |
47 * `call(**kwargs)`, call the view for a complete result set or null and call |
47 * `call(**kwargs)`, call the view for a complete result set or null (default |
48 the method `cell_call()` on each cell of the result set |
48 implementation calls `cell_call()` on each cell of the result set) |
49 * `cell_call(row, col, **kwargs)`, call the view for a given cell of a result set |
49 * `cell_call(row, col, **kwargs)`, call the view for a given cell of a result set |
50 * `url()`, returns the URL enabling us to get the view with the current |
50 * `url()`, returns the URL enabling us to get the view with the current |
51 result set |
51 result set |
52 * `view(__vid, rset, __fallback_vid=None, **kwargs)`, call the view of identifier |
52 * `view(__vid, rset, __fallback_vid=None, **kwargs)`, call the view of identifier |
53 `__vid` on the given result set. It is possible to give a view identifier |
53 `__vid` on the given result set. It is possible to give a view identifier |