106 content such as HTML or Restructured text. |
106 content such as HTML or Restructured text. |
107 |
107 |
108 * a `Community` may be linked to a `Blog` using the `community_blog` relation |
108 * a `Community` may be linked to a `Blog` using the `community_blog` relation |
109 |
109 |
110 - ``*`` means a community may be linked to 0 to N blog, ``?`` means a blog may |
110 - ``*`` means a community may be linked to 0 to N blog, ``?`` means a blog may |
111 be linked to 0 to 1 community. For completeness, remember that you can also |
111 be linked to 0 to 1 community. For completeness, you can also use ``+`` for |
112 use ``+`` for 1 to N, and ``1`` for single, mandatory relation (e.g. one to one); |
112 1 to N, and ``1`` for single, mandatory relation (e.g. one to one); |
113 |
113 |
114 - this is a composite relation where `Community` (e.g. the subject of the |
114 - this is a composite relation where `Community` (e.g. the subject of the |
115 relation) is the composite. That means that if you delete a community, its |
115 relation) is the composite. That means that if you delete a community, its |
116 blog will be deleted as well. |
116 blog will be deleted as well. |
117 |
117 |
183 .. _TutosBaseCustomizingTheApplicationCustomViews: |
183 .. _TutosBaseCustomizingTheApplicationCustomViews: |
184 |
184 |
185 Defining your views |
185 Defining your views |
186 ~~~~~~~~~~~~~~~~~~~ |
186 ~~~~~~~~~~~~~~~~~~~ |
187 |
187 |
188 |cubicweb| provides a lot of standard views in directory |
188 |cubicweb| provides a lot of standard views in the directory |
189 :file:`cubicweb/web/views/`. We already talked about 'primary' and 'list' views, |
189 :file:`cubicweb/web/views/`. We already talked about 'primary' and 'list' views, |
190 which are views which apply to one ore more entities. |
190 which are views which apply to one ore more entities. |
191 |
191 |
192 A view is defined by a python class which includes: |
192 A view is defined by a python class which includes: |
193 |
193 |
194 - an identifier: all objects used to build the user interface in |cubicweb| are |
194 - an identifier: all objects used to build the user interface in |cubicweb| are |
195 recorded in a registry and this identifier will be used as a key in that |
195 recorded in a registry and this identifier will be used as a key in that |
196 registry. There may be multiple views for the same identifier. |
196 registry to store the view. There may be multiple views for the same identifier. |
197 |
197 |
198 - a *selector*, which is a kind of filter telling how well a view suit to a |
198 - a *selector*, which is a kind of filter telling how well a view suit to a |
199 particular context. When looking for a particular view (e.g. given an |
199 particular context. When looking for a particular view (e.g. given an |
200 identifier), |cubicweb| computes for each available view with that identifier |
200 identifier), |cubicweb| computes for each available view with that identifier |
201 a score which is returned by the selector. Then the view with the highest |
201 a score which is returned by the selector. Then the view with the highest |
329 |
329 |
330 * We set on it a selector telling that it only applies when trying to display |
330 * We set on it a selector telling that it only applies when trying to display |
331 some entity of the `Community` type. This is enough to get an higher score than |
331 some entity of the `Community` type. This is enough to get an higher score than |
332 the default view for entities of this type. |
332 the default view for entities of this type. |
333 |
333 |
334 * View applying to entities usually have to define `cell_call` as entry point, |
334 * A view that applies to an entity usually have to define the method |
335 and are given `row` and `col` arguments tell to which entity in the result set |
335 `cell_call` as an entry point. This method will received the arguments |
336 the view is applied. We can then get this entity from the result set |
336 `row` and `col` that tell to which entity in the result set the view is |
337 (`self.cw_rset`) by using the `get_entity` method. |
337 applied. We can then get this entity from the result set (`self.cw_rset`) by |
|
338 using the `get_entity` method. |
338 |
339 |
339 * To ease thing, we access our entity's attribute for display using its |
340 * To ease thing, we access our entity's attribute for display using its |
340 printable_value method, which will handle formatting and escaping when |
341 printable_value method, which will handle formatting and escaping when |
341 necessary. As you can see, you can also access attributes by their name on the |
342 necessary. As you can see, you can also access attributes by their name on the |
342 entity to get the raw value. |
343 entity to get the raw value. |
447 to build our page using true object oriented programming techniques, that no |
448 to build our page using true object oriented programming techniques, that no |
448 template language provides. |
449 template language provides. |
449 |
450 |
450 |
451 |
451 A library of standard cubes is available from `CubicWeb Forge`_, to address a |
452 A library of standard cubes is available from `CubicWeb Forge`_, to address a |
452 lot of common concerns such has manipulating people, files, things to do, etc. In |
453 lot of common concerns such has manipulating files, people, things to do, etc. In |
453 our community blog case, we could be interested for instance in functionalities |
454 our community blog case, we could be interested for instance in functionalities |
454 provided by the `comment` and `tag` cubes. The former provides threaded |
455 provided by the `comment` and `tag` cubes. The former provides threaded |
455 discussion functionalities, the latter a simple tag mechanism to classify content. |
456 discussion functionalities, the latter a simple tag mechanism to classify content. |
456 Let's say we want to try those. We will first modify our cube's :file:`__pkginfo__.py` |
457 Let's say we want to try those. We will first modify our cube's :file:`__pkginfo__.py` |
457 file: |
458 file: |
483 So in the case above we activated comments on `BlogEntry` entities and tags on |
484 So in the case above we activated comments on `BlogEntry` entities and tags on |
484 both `Community` and `BlogEntry`. Various views from both `comment` and `tag` |
485 both `Community` and `BlogEntry`. Various views from both `comment` and `tag` |
485 cubes will then be automatically displayed when one of those relations is |
486 cubes will then be automatically displayed when one of those relations is |
486 supported. |
487 supported. |
487 |
488 |
488 Let's synchronize the data model as we've done earlier: :: |
489 Let's install the cubes and synchronize the data model as we've done earlier: :: |
489 |
490 |
490 |
491 |
491 $ cubicweb-ctl stop myblog |
492 $ cubicweb-ctl stop myblog |
492 $ cubicweb-ctl shell myblog |
493 $ cubicweb-ctl shell myblog |
493 entering the migration python shell |
494 entering the migration python shell |