author | David Douard <david.douard@logilab.fr> |
Tue, 19 Jul 2016 13:50:56 +0200 | |
branch | 3.20 |
changeset 11399 | 5149a4d4cf54 |
parent 10065 | 8d4266411be5 |
child 10688 | fa29f3628a1b |
permissions | -rw-r--r-- |
9161
7b51daf84a66
[deprecation] fix uihelper deprecation warning, use the rtag name, not the class, so it may be copy/pasted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8667
diff
changeset
|
1 |
# copyright 2011-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
3 |
# |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
5 |
# |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
9 |
# any later version. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
10 |
# |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
14 |
# details. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
15 |
# |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
18 |
"""This module provide highlevel helpers to avoid uicfg boilerplate |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
19 |
for most common tasks such as fields ordering, widget customization, etc. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
20 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
21 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
22 |
Here are a few helpers to customize *action box* rendering: |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
23 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
24 |
.. autofunction:: cubicweb.web.uihelper.append_to_addmenu |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
25 |
.. autofunction:: cubicweb.web.uihelper.remove_from_addmenu |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
26 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
27 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
28 |
and a few other ones for *form configuration*: |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
29 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
30 |
.. autofunction:: cubicweb.web.uihelper.set_fields_order |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
31 |
.. autofunction:: cubicweb.web.uihelper.hide_field |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
32 |
.. autofunction:: cubicweb.web.uihelper.hide_fields |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
33 |
.. autofunction:: cubicweb.web.uihelper.set_field_kwargs |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
34 |
.. autofunction:: cubicweb.web.uihelper.set_field |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
35 |
.. autofunction:: cubicweb.web.uihelper.edit_inline |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
36 |
.. autofunction:: cubicweb.web.uihelper.edit_as_attr |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
37 |
.. autofunction:: cubicweb.web.uihelper.set_muledit_editable |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
The module also provides a :class:`FormConfig` base class that lets you gather |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
40 |
uicfg declaration in the scope of a single class, which can sometimes |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
41 |
be clearer to read than a bunch of sequential function calls. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
42 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
.. autoclass:: cubicweb.web.uihelper.FormConfig |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
44 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
45 |
""" |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
46 |
__docformat__ = "restructuredtext en" |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
47 |
|
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
48 |
|
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
49 |
from logilab.common.deprecation import deprecated |
8665
e65af61bde7d
[uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8238
diff
changeset
|
50 |
from cubicweb.web.views import uicfg |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
51 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
52 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
53 |
## generic uicfg helpers ###################################################### |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
54 |
|
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
55 |
backward_compat_funcs = (('append_to_addmenu', uicfg.actionbox_appearsin_addmenu), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
56 |
('remove_from_addmenu', uicfg.actionbox_appearsin_addmenu), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
57 |
('set_fields_order', uicfg.autoform_field_kwargs), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
58 |
('hide_field', uicfg.autoform_section), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
59 |
('hide_fields', uicfg.autoform_section), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
60 |
('set_field_kwargs', uicfg.autoform_field_kwargs), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
61 |
('set_field', uicfg.autoform_field), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
62 |
('edit_inline', uicfg.autoform_section), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
63 |
('edit_as_attr', uicfg.autoform_section), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
64 |
('set_muledit_editable', uicfg.autoform_section), |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
65 |
) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
66 |
|
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
67 |
for funcname, tag in backward_compat_funcs: |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
68 |
msg = ('[3.16] uihelper.%(name)s is deprecated, please use ' |
9161
7b51daf84a66
[deprecation] fix uihelper deprecation warning, use the rtag name, not the class, so it may be copy/pasted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8667
diff
changeset
|
69 |
'web.views.uicfg.%(rtagid)s.%(name)s' % dict( |
7b51daf84a66
[deprecation] fix uihelper deprecation warning, use the rtag name, not the class, so it may be copy/pasted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8667
diff
changeset
|
70 |
name=funcname, rtagid=tag.__regid__)) |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
71 |
globals()[funcname] = deprecated(msg)(getattr(tag, funcname)) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
72 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
73 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
74 |
class meta_formconfig(type): |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
75 |
"""metaclass of FormConfig classes, only for easier declaration purpose""" |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
76 |
def __init__(cls, name, bases, classdict): |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
77 |
if cls.etype is None: |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
78 |
return |
10065
8d4266411be5
[uihelper] Fix a possible NameError in meta_formconfig
Florent Cayré <florent.cayre@gmail.com>
parents:
9161
diff
changeset
|
79 |
uicfg_afs = cls.uicfg_afs or uicfg.autoform_section |
8d4266411be5
[uihelper] Fix a possible NameError in meta_formconfig
Florent Cayré <florent.cayre@gmail.com>
parents:
9161
diff
changeset
|
80 |
uicfg_aff = cls.uicfg_aff or uicfg.autoform_field |
8d4266411be5
[uihelper] Fix a possible NameError in meta_formconfig
Florent Cayré <florent.cayre@gmail.com>
parents:
9161
diff
changeset
|
81 |
uicfg_affk = cls.uicfg_affk or uicfg.autoform_field_kwargs |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
82 |
for attr_role in cls.hidden: |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
83 |
uicfg_afs.hide_field(cls.etype, attr_role, formtype=cls.formtype) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
84 |
for attr_role in cls.rels_as_attrs: |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
85 |
uicfg_afs.edit_as_attr(cls.etype, attr_role, formtype=cls.formtype) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
86 |
for attr_role in cls.inlined: |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
87 |
uicfg_afs.edit_inline(cls.etype, attr_role, formtype=cls.formtype) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
88 |
for rtype, widget in cls.widgets.items(): |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
89 |
uicfg_affk.set_field_kwargs(cls.etype, rtype, widget=widget) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
90 |
for rtype, field in cls.fields.items(): |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
91 |
uicfg_aff.set_field(cls.etype, rtype, field) |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
92 |
uicfg_affk.set_fields_order(cls.etype, cls.fields_order) |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
93 |
super(meta_formconfig, cls).__init__(name, bases, classdict) |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
94 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
95 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
96 |
class FormConfig: |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
97 |
"""helper base class to define uicfg rules on a given entity type. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
98 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
99 |
In all descriptions below, attributes list can either be a list of |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
100 |
attribute names of a list of 2-tuples (relation name, role of |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
101 |
the edited entity in the relation). |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
102 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
103 |
**Attributes** |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
104 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
105 |
:attr:`etype` |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
106 |
which entity type the form config is for. This attribute is **mandatory** |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
107 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
108 |
:attr:`formtype` |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
109 |
the formtype the class tries toc customize (i.e. *main*, *inlined*, or *muledit*), |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
110 |
default is *main*. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
111 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
112 |
:attr:`hidden` |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
113 |
the list of attributes or relations to hide. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
114 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
115 |
:attr:`rels_as_attrs` |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
116 |
the list of attributes to edit in the *attributes* section. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
117 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
118 |
:attr:`inlined` |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
119 |
the list of attributes to edit in the *inlined* section. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
120 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
121 |
:attr:`fields_order` |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
122 |
the list of attributes to edit, in the desired order. Unspecified |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
123 |
fields will be displayed after specified ones, their order |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
124 |
being consistent with the schema definition. |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
125 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
126 |
:attr:`widgets` |
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8033
diff
changeset
|
127 |
a dictionary mapping attribute names to widget instances. |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
128 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
129 |
:attr:`fields` |
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8033
diff
changeset
|
130 |
a dictionary mapping attribute names to field instances. |
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
131 |
|
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
132 |
:attr:`uicfg_afs` |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
133 |
an instance of ``cubicweb.web.uicfg.AutoformSectionRelationTags`` |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
134 |
Default is None, meaning ``cubicweb.web.uicfg.autoform_section`` is used. |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
135 |
|
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
136 |
:attr:`uicfg_aff` |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
137 |
an instance of ``cubicweb.web.uicfg.AutoformFieldTags`` |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
138 |
Default is None, meaning ``cubicweb.web.uicfg.autoform_field`` is used. |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
139 |
|
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
140 |
:attr:`uicfg_affk` |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
141 |
an instance of ``cubicweb.web.uicfg.AutoformFieldKwargsTags`` |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
142 |
Default is None, meaning ``cubicweb.web.uicfg.autoform_field_kwargs`` is used. |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
143 |
|
8030
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
144 |
Examples: |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
145 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
146 |
.. sourcecode:: python |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
147 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
148 |
from cubicweb.web import uihelper, formwidgets as fwdgs |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
149 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
150 |
class LinkFormConfig(uihelper.FormConfig): |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
151 |
etype = 'Link' |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
152 |
hidden = ('title', 'description', 'embed') |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
153 |
widgets = dict( |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
154 |
url=fwdgs.TextInput(attrs={'size':40}), |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
155 |
) |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
156 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
157 |
class UserFormConfig(uihelper.FormConfig): |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
158 |
etype = 'CWUser' |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
159 |
hidden = ('login',) |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
160 |
rels_as_attrs = ('in_group',) |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
161 |
fields_order = ('firstname', 'surname', 'in_group', 'use_email') |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
162 |
inlined = ('use_email',) |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
163 |
|
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
164 |
""" |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
165 |
__metaclass__ = meta_formconfig |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
166 |
formtype = 'main' |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
167 |
etype = None # must be defined in concrete subclasses |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
168 |
hidden = () |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
169 |
rels_as_attrs = () |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
170 |
inlined = () |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
171 |
fields_order = () |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
172 |
widgets = {} |
552d85fcb587
[uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
173 |
fields = {} |
8667
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
174 |
uicfg_afs = None |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
175 |
uicfg_aff = None |
5a394fc419b4
[web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8665
diff
changeset
|
176 |
uicfg_affk = None |