author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Thu, 14 Apr 2011 14:41:40 +0200 | |
changeset 7281 | daee8aec3b9b |
parent 6906 | 5f13aefb470b |
child 7582 | dd4487c3f21e |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5368
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
18 |
""" |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
19 |
Base form classes |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
20 |
----------------- |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
21 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
22 |
.. Note: |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
23 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
24 |
Form is the glue that bind a context to a set of fields, and is rendered |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
25 |
using a form renderer. No display is actually done here, though you'll find |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
26 |
some attributes of form that are used to control the rendering process. |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
|
5464
c6c9a80ad1dd
[doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5424
diff
changeset
|
28 |
Besides the automagic form we'll see later, there are roughly two main |
c6c9a80ad1dd
[doc/book] dissection of a form chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5424
diff
changeset
|
29 |
form classes in |cubicweb|: |
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
30 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
31 |
.. autoclass:: cubicweb.web.views.forms.FieldsForm |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
32 |
.. autoclass:: cubicweb.web.views.forms.EntityFieldsForm |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
33 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
34 |
As you have probably guessed, choosing between them is easy. Simply ask you the |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
35 |
question 'I am editing an entity or not?'. If the answer is yes, use |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
36 |
:class:`EntityFieldsForm`, else use :class:`FieldsForm`. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
37 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
38 |
Actually there exists a third form class: |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
39 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
40 |
.. autoclass:: cubicweb.web.views.forms.CompositeForm |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
41 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
42 |
but you'll use this one rarely. |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
""" |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
__docformat__ = "restructuredtext en" |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
46 |
from warnings import warn |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
47 |
|
4236
9260403bfe0b
move autoform's field_by_name implementation on base EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4224
diff
changeset
|
48 |
from logilab.common.decorators import iclassmethod |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
from logilab.common.compat import any |
3953
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
50 |
from logilab.common.deprecation import deprecated |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
|
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
52 |
from cubicweb import typed_eid |
6584
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
53 |
from cubicweb.utils import support_args |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
54 |
from cubicweb.selectors import non_final_entity, match_kwargs, one_line_rset |
4236
9260403bfe0b
move autoform's field_by_name implementation on base EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4224
diff
changeset
|
55 |
from cubicweb.web import uicfg, form, formwidgets as fwdgs |
5367
4176a50c81c9
[form] small api cleanup and refactoring before documenting the form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
56 |
from cubicweb.web.formfields import relvoc_unrelated, guess_field |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
57 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
58 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
59 |
class FieldsForm(form.Form): |
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
60 |
"""This is the base class for fields based forms. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
61 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
62 |
**Attributes** |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
63 |
|
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
64 |
The following attributes may be either set on subclasses or given on |
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
65 |
form selection to customize the generated form: |
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
66 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
67 |
:attr:`needs_js` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
68 |
sequence of javascript files that should be added to handle this form |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
69 |
(through :meth:`~cubicweb.web.request.Request.add_js`) |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
70 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
71 |
:attr:`needs_css` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
72 |
sequence of css files that should be added to handle this form (through |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
73 |
:meth:`~cubicweb.web.request.Request.add_css`) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
74 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
75 |
:attr:`domid` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
76 |
value for the "id" attribute of the <form> tag |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
77 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
78 |
:attr:`action` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
79 |
value for the "action" attribute of the <form> tag |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
80 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
81 |
:attr:`onsubmit` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
82 |
value for the "onsubmit" attribute of the <form> tag |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
83 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
84 |
:attr:`cssclass` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
85 |
value for the "class" attribute of the <form> tag |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
86 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
87 |
:attr:`cssstyle` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
88 |
value for the "style" attribute of the <form> tag |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
89 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
90 |
:attr:`cwtarget` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
91 |
value for the "cubicweb:target" attribute of the <form> tag |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
92 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
93 |
:attr:`redirect_path` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
94 |
relative to redirect to after submitting the form |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
95 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
96 |
:attr:`copy_nav_params` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
97 |
flag telling if navigation parameters should be copied back in hidden |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
98 |
inputs |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
99 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
100 |
:attr:`form_buttons` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
101 |
sequence of form control (:class:`~cubicweb.web.formwidgets.Button` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
102 |
widgets instances) |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
103 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
104 |
:attr:`form_renderer_id` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
105 |
identifier of the form renderer to use to render the form |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
106 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
107 |
:attr:`fieldsets_in_order` |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
108 |
sequence of fieldset names , to control order |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
109 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
110 |
**Generic methods** |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
111 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
112 |
.. automethod:: cubicweb.web.form.Form.field_by_name(name, role=None) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
113 |
.. automethod:: cubicweb.web.form.Form.fields_by_name(name, role=None) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
114 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
115 |
**Form construction methods** |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
116 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
117 |
.. automethod:: cubicweb.web.form.Form.remove_field(field) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
118 |
.. automethod:: cubicweb.web.form.Form.append_field(field) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
119 |
.. automethod:: cubicweb.web.form.Form.insert_field_before(field, name, role=None) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
120 |
.. automethod:: cubicweb.web.form.Form.insert_field_after(field, name, role=None) |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
121 |
.. automethod:: cubicweb.web.form.Form.add_hidden(name, value=None, **kwargs) |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
122 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
123 |
**Form rendering methods** |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
124 |
|
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
125 |
.. automethod:: cubicweb.web.views.forms.FieldsForm.render |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
126 |
|
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
127 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
128 |
__regid__ = 'base' |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
129 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
130 |
|
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
131 |
# attributes overrideable by subclasses or through __init__ |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
132 |
needs_js = ('cubicweb.ajax.js', 'cubicweb.edition.js',) |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
needs_css = ('cubicweb.form.css',) |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
134 |
action = None |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
135 |
onsubmit = "return freezeFormButtons('%(domid)s');" |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
136 |
cssclass = None |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
137 |
cssstyle = None |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
138 |
cwtarget = None |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
redirect_path = None |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
140 |
form_buttons = None |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
141 |
form_renderer_id = 'default' |
2573
9c414dbc76da
add default values for fielsets_in_order, document base form attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2293
diff
changeset
|
142 |
fieldsets_in_order = None |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
143 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
144 |
@property |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
145 |
def needs_multipart(self): |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
146 |
"""true if the form needs enctype=multipart/form-data""" |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
147 |
return any(field.needs_multipart for field in self.fields) |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
148 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
149 |
def add_media(self): |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
"""adds media (CSS & JS) required by this widget""" |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
151 |
if self.needs_js: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
152 |
self._cw.add_js(self.needs_js) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
153 |
if self.needs_css: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
154 |
self._cw.add_css(self.needs_css) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
155 |
|
4167
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
156 |
def render(self, formvalues=None, rendervalues=None, renderer=None, **kwargs): |
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
157 |
"""Render this form, using the `renderer` given as argument or the |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
158 |
default according to :attr:`form_renderer_id`. The rendered form is |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
159 |
returned as an unicode string. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
160 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
161 |
`formvalues` is an optional dictionary containing values that will be |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
162 |
considered as field's value. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
163 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
164 |
Extra keyword arguments will be given to renderer's :meth:`render` method. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
165 |
|
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
166 |
`rendervalues` is deprecated. |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
167 |
""" |
4167
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
168 |
if rendervalues is not None: |
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
169 |
warn('[3.6] rendervalues argument is deprecated, all named arguments will be given instead', |
4284
8e5dcb54fd8e
fix warning stack level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4260
diff
changeset
|
170 |
DeprecationWarning, stacklevel=2) |
4167
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
171 |
kwargs = rendervalues |
6453
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
172 |
w = kwargs.pop('w', None) |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
173 |
if w is None: |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
174 |
warn('[3.10] you should specify "w" to form.render() named arguments', |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
175 |
DeprecationWarning, stacklevel=2) |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
176 |
data = [] |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
177 |
w = data.append |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
178 |
else: |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
179 |
data = None |
4167
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
180 |
self.build_context(formvalues) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
181 |
if renderer is None: |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
182 |
renderer = self.default_renderer() |
6584
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
183 |
if support_args(renderer.render, 'w'): |
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
184 |
renderer.render(w, self, kwargs) |
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
185 |
else: |
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
186 |
warn('[3.10] you should add "w" as first argument o %s.render()' |
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
187 |
% renderer.__class__, DeprecationWarning) |
c4aa6186d3a3
[3.10] renderer.render prototype bw compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6453
diff
changeset
|
188 |
w(renderer.render(self, kwargs)) |
6453
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
189 |
if data is not None: |
7fdd780d87e4
[form] unify form.render prototype to take a 'w' argument as other view/components render method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6246
diff
changeset
|
190 |
return '\n'.join(data) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
191 |
|
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
192 |
def default_renderer(self): |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
193 |
return self._cw.vreg['formrenderers'].select( |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
194 |
self.form_renderer_id, self._cw, |
4697
b8263d717e74
[web] fix muledit rendering bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4668
diff
changeset
|
195 |
rset=self.cw_rset, row=self.cw_row, col=self.cw_col or 0) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
196 |
|
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
197 |
formvalues = None |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
198 |
def build_context(self, formvalues=None): |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
199 |
"""build form context values (the .context attribute which is a |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
200 |
dictionary with field instance as key associated to a dictionary |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
201 |
containing field 'name' (qualified), 'id', 'value' (for display, always |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
202 |
a string). |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
203 |
""" |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
204 |
if self.formvalues is not None: |
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
205 |
return # already built |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
206 |
self.formvalues = formvalues or {} |
6246
62e25fac41cd
[views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5656
diff
changeset
|
207 |
# use a copy in case fields are modified while context is built (eg |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
208 |
# __linkto handling for instance) |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
209 |
for field in self.fields[:]: |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
210 |
for field in field.actual_fields(self): |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
211 |
field.form_init(self) |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
212 |
|
5588
377c9adfe81e
[forms]Â refactor action handling to ease overriding while keeping action overrideable by instance (closes #969167)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5547
diff
changeset
|
213 |
_default_form_action_path = 'edit' |
377c9adfe81e
[forms]Â refactor action handling to ease overriding while keeping action overrideable by instance (closes #969167)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5547
diff
changeset
|
214 |
def form_action(self): |
5656
abe97430b3f5
[form] avoid spurious warning subsequent for form's action refactoring w/ autoforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5598
diff
changeset
|
215 |
try: |
abe97430b3f5
[form] avoid spurious warning subsequent for form's action refactoring w/ autoforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5598
diff
changeset
|
216 |
action = self.get_action() # avoid spurious warning w/ autoform bw compat property |
abe97430b3f5
[form] avoid spurious warning subsequent for form's action refactoring w/ autoforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5598
diff
changeset
|
217 |
except AttributeError: |
abe97430b3f5
[form] avoid spurious warning subsequent for form's action refactoring w/ autoforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5598
diff
changeset
|
218 |
action = self.action |
abe97430b3f5
[form] avoid spurious warning subsequent for form's action refactoring w/ autoforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5598
diff
changeset
|
219 |
if action is None: |
5598
0a68e7f5829c
[form] missing return...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5588
diff
changeset
|
220 |
return self._cw.build_url(self._default_form_action_path) |
5656
abe97430b3f5
[form] avoid spurious warning subsequent for form's action refactoring w/ autoforms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5598
diff
changeset
|
221 |
return action |
5588
377c9adfe81e
[forms]Â refactor action handling to ease overriding while keeping action overrideable by instance (closes #969167)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5547
diff
changeset
|
222 |
|
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
223 |
@deprecated('[3.6] use .add_hidden(name, value, **kwargs)') |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
224 |
def form_add_hidden(self, name, value=None, **kwargs): |
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
225 |
return self.add_hidden(name, value, **kwargs) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
226 |
|
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
227 |
@deprecated('[3.6] use .render(formvalues, **rendervalues)') |
3953
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
228 |
def form_render(self, **values): |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
229 |
"""render this form, using the renderer given in args or the default |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
230 |
FormRenderer() |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
231 |
""" |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
232 |
self.build_context(values) |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
233 |
renderer = values.pop('renderer', None) |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
234 |
if renderer is None: |
4260
832b578839cb
[forms] fix implementation of backward compat method form_render
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4257
diff
changeset
|
235 |
renderer = self.default_renderer() |
3953
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
236 |
return renderer.render(self, values) |
19aefd78f61b
[forms] deprecate form_render(**kwargs) in favor of render(formvalues=None, rendervalues=None, renderer=None)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3923
diff
changeset
|
237 |
|
4660 | 238 |
|
4236
9260403bfe0b
move autoform's field_by_name implementation on base EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4224
diff
changeset
|
239 |
_AFF = uicfg.autoform_field |
9260403bfe0b
move autoform's field_by_name implementation on base EntityFieldsForm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4224
diff
changeset
|
240 |
_AFF_KWARGS = uicfg.autoform_field_kwargs |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
241 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
242 |
class EntityFieldsForm(FieldsForm): |
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
243 |
"""This class is designed for forms used to edit some entities. It should |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
244 |
handle for you all the underlying stuff necessary to properly work with the |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
245 |
generic :class:`~cubicweb.web.views.editcontroller.EditController`. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
246 |
""" |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
247 |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
248 |
__regid__ = 'base' |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
249 |
__select__ = (match_kwargs('entity') |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
250 |
| (one_line_rset() & non_final_entity())) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
251 |
domid = 'entityForm' |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
252 |
|
4257
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
253 |
@iclassmethod |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
254 |
def field_by_name(cls_or_self, name, role=None, eschema=None): |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
255 |
"""return field with the given name and role. If field is not explicitly |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
256 |
defined for the form but `eclass` is specified, guess_field will be |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
257 |
called. |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
258 |
""" |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
259 |
try: |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
260 |
return super(EntityFieldsForm, cls_or_self).field_by_name(name, role) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
261 |
except form.FieldNotFound: |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
262 |
if eschema is None or role is None or not name in eschema.schema: |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
263 |
raise |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
264 |
rschema = eschema.schema.rschema(name) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
265 |
# XXX use a sample target type. Document this. |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
266 |
tschemas = rschema.targets(eschema, role) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
267 |
fieldcls = _AFF.etype_get(eschema, rschema, role, tschemas[0]) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
268 |
kwargs = _AFF_KWARGS.etype_get(eschema, rschema, role, tschemas[0]) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
269 |
if kwargs is None: |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
270 |
kwargs = {} |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
271 |
if fieldcls: |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
272 |
if not isinstance(fieldcls, type): |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
273 |
return fieldcls # already and instance |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
274 |
return fieldcls(name=name, role=role, eidparam=True, **kwargs) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
275 |
field = guess_field(eschema, rschema, role, eidparam=True, **kwargs) |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
276 |
if field is None: |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
277 |
raise |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
278 |
return field |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
279 |
|
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
280 |
def __init__(self, _cw, rset=None, row=None, col=None, **kwargs): |
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
281 |
try: |
4206
cebdf8ee5ad7
[forms] edited_entity must be set before calling session_key()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4134
diff
changeset
|
282 |
self.edited_entity = kwargs.pop('entity') |
4257
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
283 |
except KeyError: |
4252 | 284 |
self.edited_entity = rset.complete_entity(row or 0, col or 0) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
285 |
msg = kwargs.pop('submitmsg', None) |
4257
0a9b38a492e1
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
286 |
super(EntityFieldsForm, self).__init__(_cw, rset, row, col, **kwargs) |
4659
f8326ff98f37
[form] complete 25de2eb0432b by ignore req parameters by default for all hidden fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4658
diff
changeset
|
287 |
self.add_hidden('__type', self.edited_entity.__regid__, eidparam=True) |
f8326ff98f37
[form] complete 25de2eb0432b by ignore req parameters by default for all hidden fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4658
diff
changeset
|
288 |
self.add_hidden('eid', self.edited_entity.eid) |
6906
5f13aefb470b
[forms] EntityFieldsForm now take extra mainentity argument, for usage with composite form (the main form) where one of the subform edits the main entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6584
diff
changeset
|
289 |
# mainform default to true in parent, hence default to True |
5f13aefb470b
[forms] EntityFieldsForm now take extra mainentity argument, for usage with composite form (the main form) where one of the subform edits the main entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6584
diff
changeset
|
290 |
if kwargs.get('mainform', True) or kwargs.get('mainentity', False): |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
291 |
self.add_hidden(u'__maineid', self.edited_entity.eid) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
292 |
# If we need to directly attach the new object to another one |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
293 |
if self._cw.list_form_param('__linkto'): |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
294 |
for linkto in self._cw.list_form_param('__linkto'): |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
295 |
self.add_hidden('__linkto', linkto) |
2050
ce184fdb1e56
fix submit message handling in entity form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2049
diff
changeset
|
296 |
if msg: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
297 |
msg = '%s %s' % (msg, self._cw._('and linked')) |
2050
ce184fdb1e56
fix submit message handling in entity form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2049
diff
changeset
|
298 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
299 |
msg = self._cw._('entity linked') |
2050
ce184fdb1e56
fix submit message handling in entity form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2049
diff
changeset
|
300 |
if msg: |
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
301 |
self.add_hidden('__message', msg) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
302 |
|
3922
69020a7c234a
refactor session_key (__errorurl) to handle cases where the form is generated throuhg an ajax call: in case of an entity form, return the entity's absolute url. Also allow to force session key value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3880
diff
changeset
|
303 |
def session_key(self): |
69020a7c234a
refactor session_key (__errorurl) to handle cases where the form is generated throuhg an ajax call: in case of an entity form, return the entity's absolute url. Also allow to force session key value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3880
diff
changeset
|
304 |
"""return the key that may be used to store / retreive data about a |
69020a7c234a
refactor session_key (__errorurl) to handle cases where the form is generated throuhg an ajax call: in case of an entity form, return the entity's absolute url. Also allow to force session key value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3880
diff
changeset
|
305 |
previous post which failed because of a validation error |
69020a7c234a
refactor session_key (__errorurl) to handle cases where the form is generated throuhg an ajax call: in case of an entity form, return the entity's absolute url. Also allow to force session key value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3880
diff
changeset
|
306 |
""" |
4133
24ffe983abfc
force_session_key default to None in base form class...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3953
diff
changeset
|
307 |
if self.force_session_key is not None: |
3922
69020a7c234a
refactor session_key (__errorurl) to handle cases where the form is generated throuhg an ajax call: in case of an entity form, return the entity's absolute url. Also allow to force session key value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3880
diff
changeset
|
308 |
return self.force_session_key |
4133
24ffe983abfc
force_session_key default to None in base form class...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3953
diff
changeset
|
309 |
# XXX if this is a json request, suppose we should redirect to the |
24ffe983abfc
force_session_key default to None in base form class...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3953
diff
changeset
|
310 |
# entity primary view |
4183
b5aa030bb2f9
use ._cw instead of .req (reintroduced by merge of stable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4181
diff
changeset
|
311 |
if self._cw.json_request and self.edited_entity.has_eid(): |
4133
24ffe983abfc
force_session_key default to None in base form class...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3953
diff
changeset
|
312 |
return '%s#%s' % (self.edited_entity.absolute_url(), self.domid) |
4662
79c0788ba7f6
add XXX note
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4660
diff
changeset
|
313 |
# XXX we should not consider some url parameters that may lead to |
79c0788ba7f6
add XXX note
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4660
diff
changeset
|
314 |
# different url after a validation error |
4183
b5aa030bb2f9
use ._cw instead of .req (reintroduced by merge of stable)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4181
diff
changeset
|
315 |
return '%s#%s' % (self._cw.url(), self.domid) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
316 |
|
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
317 |
def build_context(self, formvalues=None): |
4248
d375643eea43
don't add another _cw_edited_field hidden when build_context is called twice (may occurs with inlined relation forms)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4236
diff
changeset
|
318 |
if self.formvalues is not None: |
d375643eea43
don't add another _cw_edited_field hidden when build_context is called twice (may occurs with inlined relation forms)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4236
diff
changeset
|
319 |
return # already built |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
320 |
super(EntityFieldsForm, self).build_context(formvalues) |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
321 |
edited = set() |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
322 |
for field in self.fields: |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
323 |
if field.eidparam: |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
324 |
edited.add(field.role_name()) |
4660 | 325 |
self.add_hidden('_cw_edited_fields', u','.join(edited), eidparam=True) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
326 |
|
4164
119a374c5eb4
form_add_hidden -> add_hidden
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4162
diff
changeset
|
327 |
def default_renderer(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
328 |
return self._cw.vreg['formrenderers'].select( |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
329 |
self.form_renderer_id, self._cw, rset=self.cw_rset, row=self.cw_row, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3396
diff
changeset
|
330 |
col=self.cw_col, entity=self.edited_entity) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
331 |
|
4583 | 332 |
def should_display_add_new_relation_link(self, rschema, existant, card): |
333 |
return False |
|
334 |
||
4167
73e649a7797d
fix render (formerly form_render) prototype
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4164
diff
changeset
|
335 |
# controller side method (eg POST reception handling) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
336 |
|
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
337 |
def actual_eid(self, eid): |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
338 |
# should be either an int (existant entity) or a variable (to be |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
339 |
# created entity) |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
340 |
assert eid or eid == 0, repr(eid) # 0 is a valid eid |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
341 |
try: |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
342 |
return typed_eid(eid) |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
343 |
except ValueError: |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
344 |
try: |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
345 |
return self._cw.data['eidmap'][eid] |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
346 |
except KeyError: |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
347 |
self._cw.data['eidmap'][eid] = None |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
348 |
return None |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
349 |
|
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3467
diff
changeset
|
350 |
def editable_relations(self): |
2089
b1070848726b
backport default branch fix 4ec37d33657e (EntityFieldsForm methods implementation)
Florent <florent@secondweb.fr>
parents:
2080
diff
changeset
|
351 |
return () |
b1070848726b
backport default branch fix 4ec37d33657e (EntityFieldsForm methods implementation)
Florent <florent@secondweb.fr>
parents:
2080
diff
changeset
|
352 |
|
4161
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
353 |
@deprecated('[3.6] use cw.web.formfields.relvoc_unrelated function') |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
354 |
def subject_relation_vocabulary(self, rtype, limit=None): |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
355 |
"""defaut vocabulary method for the given relation, looking for |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
356 |
relation's object entities (i.e. self is the subject) |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
357 |
""" |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
358 |
return relvoc_unrelated(self.edited_entity, rtype, 'subject', limit=None) |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
359 |
|
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
360 |
@deprecated('[3.6] use cw.web.formfields.relvoc_unrelated function') |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
361 |
def object_relation_vocabulary(self, rtype, limit=None): |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
362 |
return relvoc_unrelated(self.edited_entity, rtype, 'object', limit=None) |
4273f5094651
refactor vocabulary handling to avoid having to define methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4159
diff
changeset
|
363 |
|
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
364 |
|
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
365 |
class CompositeFormMixIn(object): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
366 |
__regid__ = 'composite' |
3467
a6405235aac6
[tests] make unittest_views_editforms pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
367 |
form_renderer_id = __regid__ |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
368 |
|
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
369 |
def __init__(self, *args, **kwargs): |
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
370 |
super(CompositeFormMixIn, self).__init__(*args, **kwargs) |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
371 |
self.forms = [] |
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
372 |
|
3513
c002f6488631
[form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3512
diff
changeset
|
373 |
def add_subform(self, subform): |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
374 |
"""mark given form as a subform and append it""" |
3513
c002f6488631
[form] replace is_subform by parent_form, carrying more information at the same cost
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3512
diff
changeset
|
375 |
subform.parent_form = self |
2005
e8032965f37a
turn every form class into appobject. They should not be instantiated manually anymore.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
376 |
self.forms.append(subform) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
377 |
|
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
378 |
def build_context(self, formvalues=None): |
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
379 |
super(CompositeFormMixIn, self).build_context(formvalues) |
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
380 |
for form in self.forms: |
4159
6b2b20c73d59
refactor form field value handling, to get a nicer api and an easier algorithm to get field's value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4156
diff
changeset
|
381 |
form.build_context(formvalues) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
382 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
383 |
|
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
384 |
class CompositeForm(CompositeFormMixIn, FieldsForm): |
5368
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
385 |
"""Form composed of sub-forms. Typical usage is edition of multiple entities |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
386 |
at once. |
d321e4b62a10
[book] start documenting the HTML form system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5367
diff
changeset
|
387 |
""" |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
388 |
|
3510
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
389 |
class CompositeEntityForm(CompositeFormMixIn, EntityFieldsForm): |
bf746bf4a394
rename form_build_context to build_context, and call it from form, not renderer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3354
diff
changeset
|
390 |
pass # XXX why is this class necessary? |