web/uihelper.py
author Katia Saurfelt <katia.saurfelt@logilab.fr>
Wed, 03 Jul 2013 14:48:34 +0200
branchstable
changeset 9135 d42540bacff4
parent 8667 5a394fc419b4
child 9161 7b51daf84a66
permissions -rw-r--r--
[facet] don't crash if no title specified on a facet and filtered rset is empty. Closes #2587883
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
     1
# copyright 2011-2012 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 '
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    69
           'web.uicfg.%(classname)s.%(name)s' % dict(
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    70
               name=funcname, classname=tag.__class__.__name__))
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
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    79
        if cls.uicfg_afs is None:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    80
            uicfg_afs = 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
    81
        if cls.uicfg_aff is None:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    82
            uicfg_aff = 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
    83
        if cls.uicfg_affk is None:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
    84
            uicfg_affk = 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
    85
        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
    86
            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
    87
        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
    88
            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
    89
        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
    90
            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
    91
        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
    92
            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
    93
        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
    94
            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
    95
        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
    96
        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
    97
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
class FormConfig:
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
    """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
   101
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    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
   103
    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
   104
    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
   105
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    **Attributes**
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:`etype`
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
      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
   110
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
    :attr:`formtype`
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
      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
   113
      default is *main*.
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:`hidden`
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 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
   117
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    :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
   119
      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
   120
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    :attr:`inlined`
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 *inlined* section.
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
    :attr:`fields_order`
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
      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
   126
      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
   127
      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
   128
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
    :attr:`widgets`
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 widget instances.
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
    :attr:`fields`
8238
087bb529035c [spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8033
diff changeset
   133
      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
   134
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   135
    :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
   136
      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
   137
      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
   138
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   139
    :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
   140
      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
   141
      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
   142
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8665
diff changeset
   143
    :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
   144
      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
   145
      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
   146
8030
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
    Examples:
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
.. sourcecode:: python
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
  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
   152
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
  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
   154
      etype = 'Link'
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
      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
   156
      widgets = dict(
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
          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
   158
          )
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
  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
   161
      etype = 'CWUser'
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
      hidden = ('login',)
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
      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
   164
      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
   165
      inlined = ('use_email',)
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
    """
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    __metaclass__ = meta_formconfig
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
    formtype = 'main'
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
    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
   171
    hidden = ()
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
    rels_as_attrs = ()
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    inlined = ()
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    fields_order = ()
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
    widgets = {}
552d85fcb587 [uicfg] add uihelper module with high-level helpers (closes #1809414)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
    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
   177
    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
   178
    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
   179
    uicfg_affk = None