151 __selectors__ = (one_line_rset, match_search_state, accept_selector) |
151 __selectors__ = (one_line_rset, match_search_state, accept_selector) |
152 accepts = ('Any',) |
152 accepts = ('Any',) |
153 search_states = ('linksearch',) |
153 search_states = ('linksearch',) |
154 |
154 |
155 |
155 |
156 |
156 Rendering methods and attributes for ``PrimaryView`` |
157 |
157 ---------------------------------------------------- |
|
158 |
|
159 By default, `CubicWeb` provides a primary view for each new entity type |
|
160 you create. The first view you might be interested in modifying. |
|
161 |
|
162 Let's have a quick look at the EntityView ``PrimaryView`` as well as |
|
163 its rendering method:: |
|
164 |
|
165 class PrimaryView(EntityView): |
|
166 """the full view of an non final entity""" |
|
167 id = 'primary' |
|
168 title = _('primary') |
|
169 show_attr_label = True |
|
170 show_rel_label = True |
|
171 skip_none = True |
|
172 skip_attrs = ('eid', 'creation_date', 'modification_date') |
|
173 skip_rels = () |
|
174 main_related_section = True |
|
175 |
|
176 ... |
|
177 |
|
178 def cell_call(self, row, col): |
|
179 self.row = row |
|
180 self.render_entity(self.complete_entity(row, col)) |
|
181 |
|
182 def render_entity(self, entity): |
|
183 """return html to display the given entity""" |
|
184 siderelations = [] |
|
185 self.render_entity_title(entity) |
|
186 self.render_entity_metadata(entity) |
|
187 # entity's attributes and relations, excluding meta data |
|
188 # if the entity isn't meta itself |
|
189 self.w(u'<div>') |
|
190 self.w(u'<div class="mainInfo">') |
|
191 self.render_entity_attributes(entity, siderelations) |
|
192 self.w(u'</div>') |
|
193 self.content_navigation_components('navcontenttop') |
|
194 if self.main_related_section: |
|
195 self.render_entity_relations(entity, siderelations) |
|
196 self.w(u'</div>') |
|
197 # side boxes |
|
198 self.w(u'<div class="primaryRight">') |
|
199 self.render_side_related(entity, siderelations) |
|
200 self.w(u'</div>') |
|
201 self.w(u'<div class="clear"></div>') |
|
202 self.content_navigation_components('navcontentbottom') |
|
203 |
|
204 ... |
|
205 |
|
206 ``cell_call`` is executed for each entity of a result set and apply ``render_entity``. |
|
207 |
|
208 The methods you want to modify while customizing a ``PrimaryView`` are: |
|
209 |
|
210 *render_entity_title(self, entity)* |
|
211 Renders the entity title based on the assumption that the method |
|
212 ``def content_title(self)`` is implemented for the given entity type. |
|
213 |
|
214 *render_entity_metadata(self, entity)* |
|
215 Renders the entity metadata based on the assumption that the method |
|
216 ``def summary(self)`` is implemented for the given entity type. |
|
217 |
|
218 *render_entity_attributes(self, entity, siderelations)* |
|
219 Renders all the attribute of an entity with the exception of attribute |
|
220 of type `Password` and `Bytes`. |
|
221 |
|
222 *content_navigation_components(self, context)* |
|
223 |
|
224 *render_entity_relations(self, entity, siderelations)* |
|
225 Renders all the relations of the entity. |
|
226 |
|
227 *render_side_related(self, entity, siderelations)* |
|
228 Renders side related relations. |
|
229 |
|
230 Also, please note that by setting the following attributes in you class, |
|
231 you can already customize some of the rendering: |
|
232 |
|
233 *show_attr_label* |
|
234 Renders the attribute label next to the attribute value if set to True. |
|
235 Otherwise, does only display the attribute value. |
|
236 |
|
237 *show_rel_label* |
|
238 Renders the relation label next to the relation value if set to True. |
|
239 Otherwise, does only display the relation value. |
|
240 |
|
241 *skip_none* |
|
242 Does not render an attribute value that is None if set to True. |
|
243 |
|
244 *skip_attrs* |
|
245 Given a list of attributes name, does not render the value of the attributes listed. |
|
246 |
|
247 *skip_rels* |
|
248 Given a list of relations name, does not render the relations listed. |
|
249 |
|
250 *main_related_section* |
|
251 Renders the relations of the entity if set to True. |
|
252 |
|
253 A good practice is for you to identify the content of your entity type for which |
|
254 the default rendering does not answer your need so that you can focus on the specific |
|
255 method (from the list above) that needs to be modified. We do not recommand you to |
|
256 overwrite ``render_entity`` as you might potentially loose the benefits of the side |
|
257 boxes handling. |
158 |
258 |
159 Example of a view customization |
259 Example of a view customization |
160 ------------------------------- |
260 ------------------------------- |
|
261 |
|
262 [FIXME] XXX Example needs to be rewritten as it shows how to modify cell_call which |
|
263 contredicts our advise of not modifying it. |
161 |
264 |
162 We'll show you now an example of a ``primary`` view and how to customize it. |
265 We'll show you now an example of a ``primary`` view and how to customize it. |
163 |
266 |
164 If you want to change the way a ``BlogEntry`` is displayed, just override |
267 If you want to change the way a ``BlogEntry`` is displayed, just override |
165 the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py`` :: |
268 the method ``cell_call()`` of the view ``primary`` in ``BlogDemo/views.py`` :: |