equal
deleted
inserted
replaced
1 """form renderers, responsible to layout a form to html |
1 # organization: Logilab |
2 |
2 # copyright: 2009-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
3 :organization: Logilab |
3 # contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
4 :copyright: 2009-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
4 # license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 """ |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 Renderers |
|
7 --------- |
|
8 |
|
9 .. Note:: |
|
10 Form renderers are responsible to layout a form to HTML. |
|
11 |
|
12 Here are the base renderers available: |
|
13 |
|
14 .. autoclass:: cubicweb.web.views.formrenderers.FormRenderer |
|
15 .. autoclass:: cubicweb.web.views.formrenderers.HTableFormRenderer |
|
16 .. autoclass:: cubicweb.web.views.formrenderers.EntityCompositeFormRenderer |
|
17 .. autoclass:: cubicweb.web.views.formrenderers.EntityFormRenderer |
|
18 .. autoclass:: cubicweb.web.views.formrenderers.EntityInlinedFormRenderer |
|
19 |
7 """ |
20 """ |
8 __docformat__ = "restructuredtext en" |
21 __docformat__ = "restructuredtext en" |
9 |
22 |
10 from warnings import warn |
23 from warnings import warn |
11 |
24 |
35 return form._cw._(field.label) |
48 return form._cw._(field.label) |
36 |
49 |
37 |
50 |
38 |
51 |
39 class FormRenderer(AppObject): |
52 class FormRenderer(AppObject): |
40 """basic renderer displaying fields in a two columns table label | value |
53 """This is the 'default' renderer, displaying fields in a two columns table: |
41 |
54 |
42 +--------------+--------------+ |
55 +--------------+--------------+ |
43 | field1 label | field1 input | |
56 | field1 label | field1 input | |
44 +--------------+--------------+ |
57 +--------------+--------------+ |
45 | field1 label | field2 input | |
58 | field1 label | field2 input | |
254 __regid__ = 'base' |
267 __regid__ = 'base' |
255 |
268 |
256 |
269 |
257 |
270 |
258 class HTableFormRenderer(FormRenderer): |
271 class HTableFormRenderer(FormRenderer): |
259 """display fields horizontally in a table |
272 """The 'htable' form renderer display fields horizontally in a table: |
260 |
273 |
261 +--------------+--------------+---------+ |
274 +--------------+--------------+---------+ |
262 | field1 label | field2 label | | |
275 | field1 label | field2 label | | |
263 +--------------+--------------+---------+ |
276 +--------------+--------------+---------+ |
264 | field1 input | field2 input | buttons | |
277 | field1 input | field2 input | buttons | |
298 def render_buttons(self, w, form): |
311 def render_buttons(self, w, form): |
299 pass |
312 pass |
300 |
313 |
301 |
314 |
302 class EntityCompositeFormRenderer(FormRenderer): |
315 class EntityCompositeFormRenderer(FormRenderer): |
303 """specific renderer for multiple entities edition form (muledit)""" |
316 """This is a specific renderer for the multiple entities edition form |
|
317 ('muledit'). |
|
318 |
|
319 Each entity form will be displayed in row off a table, with a check box for |
|
320 each entities to indicate which ones are edited. Those checkboxes should be |
|
321 automatically updated when something is edited. |
|
322 """ |
304 __regid__ = 'composite' |
323 __regid__ = 'composite' |
305 |
324 |
306 _main_display_fields = None |
325 _main_display_fields = None |
307 |
326 |
308 def render_fields(self, w, form, values): |
327 def render_fields(self, w, form, values): |
357 else: |
376 else: |
358 self._main_display_fields = fields |
377 self._main_display_fields = fields |
359 |
378 |
360 |
379 |
361 class EntityFormRenderer(BaseFormRenderer): |
380 class EntityFormRenderer(BaseFormRenderer): |
362 """specific renderer for entity edition form (edition)""" |
381 """This is the 'default' renderer for entity's form. |
|
382 |
|
383 You can still use form_renderer_id = 'base' if you want base FormRenderer |
|
384 layout even when selected for an entity. |
|
385 """ |
363 __regid__ = 'default' |
386 __regid__ = 'default' |
364 # needs some additional points in some case (XXX explain cases) |
387 # needs some additional points in some case (XXX explain cases) |
365 __select__ = implements('Any') & yes() |
388 __select__ = implements('Any') & yes() |
366 |
389 |
367 _options = FormRenderer._options + ('main_form_title',) |
390 _options = FormRenderer._options + ('main_form_title',) |
394 else: |
417 else: |
395 super(EntityFormRenderer, self).render_buttons(w, form) |
418 super(EntityFormRenderer, self).render_buttons(w, form) |
396 |
419 |
397 |
420 |
398 class EntityInlinedFormRenderer(EntityFormRenderer): |
421 class EntityInlinedFormRenderer(EntityFormRenderer): |
399 """specific renderer for entity inlined edition form |
422 """This is a specific renderer for entity's form inlined into another |
400 (inline-[creation|edition]) |
423 entity's form. |
401 """ |
424 """ |
402 __regid__ = 'inline' |
425 __regid__ = 'inline' |
403 |
426 |
404 def render(self, form, values): |
427 def render(self, form, values): |
405 form.add_media() |
428 form.add_media() |