34 display locations and styles), a much simpler way is to use uicfg. |
34 display locations and styles), a much simpler way is to use uicfg. |
35 |
35 |
36 Attributes/relations display location |
36 Attributes/relations display location |
37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
38 |
38 |
39 In the primary view, there are 3 sections where attributes and |
39 In the primary view, there are three sections where attributes and |
40 relations can be displayed (represented in pink in the image above): |
40 relations can be displayed (represented in pink in the image above): |
41 |
41 |
42 * attributes |
42 * 'attributes' |
43 * relations |
43 * 'relations' |
44 * sideboxes |
44 * 'sideboxes' |
45 |
45 |
46 **Attributes** can only be displayed in the attributes section (default |
46 **Attributes** can only be displayed in the attributes section (default |
47 behavior). They can also be hidden. |
47 behavior). They can also be hidden. By default, attributes of type `Password` |
|
48 and `Bytes` are hidden. |
48 |
49 |
49 For instance, to hide the ``title`` attribute of the ``Blog`` entity: |
50 For instance, to hide the ``title`` attribute of the ``Blog`` entity: |
50 |
51 |
51 .. sourcecode:: python |
52 .. sourcecode:: python |
52 |
53 |
92 * ``relations`` section: 'autolimited' view |
93 * ``relations`` section: 'autolimited' view |
93 * ``sideboxes`` section: 'sidebox' view |
94 * ``sideboxes`` section: 'sidebox' view |
94 |
95 |
95 * ``order``: int used to control order within a section. When not specified, |
96 * ``order``: int used to control order within a section. When not specified, |
96 automatically set according to order in which tags are added. |
97 automatically set according to order in which tags are added. |
|
98 |
|
99 * ``label``: label for the relations section or side box |
|
100 |
|
101 * ``showlabel``: boolean telling whether the label is displayed |
97 |
102 |
98 .. sourcecode:: python |
103 .. sourcecode:: python |
99 |
104 |
100 # let us remind the schema of a blog entry |
105 # let us remind the schema of a blog entry |
101 class BlogEntry(EntityType): |
106 class BlogEntry(EntityType): |
108 # with an order different from that in the schema definition |
113 # with an order different from that in the schema definition |
109 view_ctrl = uicfg.primaryview_display_ctrl |
114 view_ctrl = uicfg.primaryview_display_ctrl |
110 for index, attr in enumerate('title', 'content', 'publish_date'): |
115 for index, attr in enumerate('title', 'content', 'publish_date'): |
111 view_ctrl.tag_attribute(('BlogEntry', attr), {'order': index}) |
116 view_ctrl.tag_attribute(('BlogEntry', attr), {'order': index}) |
112 |
117 |
113 Keys for relations only: |
118 By default, relations displayed in the 'relations' section are being displayed by |
114 |
119 the 'autolimited' view. This view will use comma separated values, or list view |
115 * ``label``: label for the relations section or side box |
120 and/or limit your rset if there is too much items in it (and generate the "view |
116 |
121 all" link in this case). |
117 * ``showlabel``: boolean telling whether the label is displayed |
122 |
118 |
123 You can control this view by setting the following values in the |
119 * ``limit``: boolean telling if the results should be limited. If so, a link to all results is displayed |
124 `primaryview_display_ctrl` relation tag: |
120 |
125 |
121 * ``filter``: callback taking the related result set as argument and returning it filtered |
126 * `limit`, maximum number of entities to display. The value of the |
|
127 'navigation.related-limit' cwproperty is used by default (which is 8 by default). |
|
128 If None, no limit. |
|
129 |
|
130 * `use_list_limit`, number of entities until which they should be display as a list |
|
131 (eg using the 'list' view). Below that limit, the 'csv' view is used. If None, |
|
132 display using 'csv' anyway. |
|
133 |
|
134 * `subvid`, the subview identifier (eg view that should be used of each item in the |
|
135 list) |
|
136 |
|
137 Notice you can also use the `filter` key to set up a callback taking the related |
|
138 result set as argument and returning it filtered, to do some arbitrary filtering |
|
139 that can't be done using rql for instance. |
|
140 |
|
141 |
|
142 |
122 |
143 |
123 .. sourcecode:: python |
144 .. sourcecode:: python |
124 |
145 |
125 pv_section = uicfg.primaryview_section |
146 pv_section = uicfg.primaryview_section |
126 # in `CWUser` primary view, display `created_by` |
147 # in `CWUser` primary view, display `created_by` |
151 |
172 |
152 The methods you may want to modify while customizing a ``PrimaryView`` |
173 The methods you may want to modify while customizing a ``PrimaryView`` |
153 are: |
174 are: |
154 |
175 |
155 *render_entity_title(self, entity)* |
176 *render_entity_title(self, entity)* |
156 Renders the entity title using the ``def dc_title(self)`` method. |
177 Renders the entity title, by default using entity's :meth:`dc_title()` method. |
157 |
|
158 *render_entity_metadata(self, entity)* |
|
159 Renders the entity metadata by calling the ``metadata`` view on the |
|
160 entity. This generic view is in cubicweb.views.baseviews. |
|
161 |
178 |
162 *render_entity_attributes(self, entity)* |
179 *render_entity_attributes(self, entity)* |
163 Renders all the attribute of an entity with the exception of |
180 Renders all attributes and relations in the 'attributes' section . The |
164 attribute of type `Password` and `Bytes`. The skip_none class |
181 :attr:`skip_none` attribute controls the display of `None` valued attributes. |
165 attribute controls the display of None valued attributes. |
|
166 |
182 |
167 *render_entity_relations(self, entity)* |
183 *render_entity_relations(self, entity)* |
168 Renders all the relations of the entity in the main section of the page. |
184 Renders all relations in the 'relations' section. |
169 |
185 |
170 *render_side_boxes(self, entity, boxes)* |
186 *render_side_boxes(self, entity, boxes)* |
171 Renders relations of the entity in a side box. |
187 Renders side boxes on the right side of the content. This will generate a box |
|
188 for each relation in the 'sidebox' section, as well as explicit box |
|
189 appobjects selectable in this context. |
172 |
190 |
173 The placement of relations in the relations section or in side boxes |
191 The placement of relations in the relations section or in side boxes |
174 can be controlled through the :ref:`primary_view_configuration` mechanism. |
192 can be controlled through the :ref:`primary_view_configuration` mechanism. |
175 |
193 |
176 *content_navigation_components(self, context)* |
194 *content_navigation_components(self, context)* |
182 |
200 |
183 Also, please note that by setting the following attributes in your |
201 Also, please note that by setting the following attributes in your |
184 subclass, you can already customize some of the rendering: |
202 subclass, you can already customize some of the rendering: |
185 |
203 |
186 *show_attr_label* |
204 *show_attr_label* |
187 Renders the attribute label next to the attribute value if set to True. |
205 Renders the attribute label next to the attribute value if set to `True`. |
188 Otherwise, does only display the attribute value. |
206 Otherwise, does only display the attribute value. |
189 |
207 |
190 *show_rel_label* |
208 *show_rel_label* |
191 Renders the relation label next to the relation value if set to True. |
209 Renders the relation label next to the relation value if set to `True`. |
192 Otherwise, does only display the relation value. |
210 Otherwise, does only display the relation value. |
193 |
211 |
194 *skip_none* |
212 *skip_none* |
195 Does not render an attribute value that is None if set to True. |
213 Does not render an attribute value that is None if set to `True`. |
196 |
214 |
197 *main_related_section* |
215 *main_related_section* |
198 Renders the relations of the entity if set to True. |
216 Renders the relations of the entity if set to `True`. |
199 |
217 |
200 A good practice is for you to identify the content of your entity type for which |
218 A good practice is for you to identify the content of your entity type for which |
201 the default rendering does not answer your need so that you can focus on the specific |
219 the default rendering does not answer your need so that you can focus on the specific |
202 method (from the list above) that needs to be modified. We do not advise you to |
220 method (from the list above) that needs to be modified. We do not advise you to |
203 overwrite ``render_entity`` unless you want a completely different layout. |
221 overwrite ``render_entity`` unless you want a completely different layout. |
|
222 |
204 |
223 |
205 Example of customization and creation |
224 Example of customization and creation |
206 ````````````````````````````````````` |
225 ````````````````````````````````````` |
207 |
226 |
208 We'll show you now an example of a ``primary`` view and how to customize it. |
227 We'll show you now an example of a ``primary`` view and how to customize it. |