web/views/uicfg.py
author Rémi Cardona <remi.cardona@logilab.fr>
Tue, 13 Oct 2015 15:09:22 +0200
changeset 10663 54b8a1f249fb
parent 10662 10942ed172de
permissions -rw-r--r--
[py3k] dict.itervalues → dict.values
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
     1
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
#
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     5
#
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
# any later version.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    10
#
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    14
# details.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
#
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    18
"""This module (``cubicweb.web.views.uicfg``) regroups a set of structures that may be
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
used to configure various options of the generated web interface.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    21
To configure the interface generation, we use ``RelationTag`` objects.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    22
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
Index view configuration
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    24
````````````````````````
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    25
:indexview_etype_section:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    26
   entity type category in the index/manage page. May be one of:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    27
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    28
      * ``application``
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    29
      * ``system``
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
      * ``schema``
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    31
      * ``subobject`` (not displayed by default)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    32
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    33
   By default only entities on the ``application`` category are shown.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    34
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
.. sourcecode:: python
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    36
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    37
    from cubicweb.web.views import uicfg
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    38
    # force hiding
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    39
    uicfg.indexview_etype_section['HideMe'] = 'subobject'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    40
    # force display
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    41
    uicfg.indexview_etype_section['ShowMe'] = 'application'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    42
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    43
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    44
Actions box configuration
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    45
`````````````````````````
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    46
:actionbox_appearsin_addmenu:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    47
  simple boolean relation tags used to control the "add entity" submenu.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    48
  Relations whose rtag is True will appears, other won't.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    49
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    50
.. sourcecode:: python
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    51
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    52
   # Adds all subjects of the entry_of relation in the add menu of the ``Blog``
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    53
   # primary view
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    54
   uicfg.actionbox_appearsin_addmenu.tag_object_of(('*', 'entry_of', 'Blog'), True)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    55
"""
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    56
__docformat__ = "restructuredtext en"
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    57
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    58
from warnings import warn
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    59
10612
84468b90e9c1 [py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
    60
from six import string_types
84468b90e9c1 [py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
    61
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    62
from cubicweb import neg_role
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    63
from cubicweb.rtags import (RelationTags, RelationTagsBool, RelationTagsSet,
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    64
                            RelationTagsDict, NoTargetRelationTagsDict,
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    65
                            _ensure_str_key)
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    66
from cubicweb.schema import META_RTYPES, INTERNAL_TYPES, WORKFLOW_TYPES
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    67
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    68
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    69
# primary view configuration ##################################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    70
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    71
class PrimaryViewSectionRelationTags(RelationTags):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    72
    """primary view section configuration"""
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    73
    __regid__ = 'primaryview_section'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    74
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    75
    _allowed_values = frozenset(('attributes', 'relations',
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    76
                                 'sideboxes', 'hidden'))
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    77
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    78
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    79
        if self.get(sschema, rschema, oschema, role) is None:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    80
            rdef = rschema.rdef(sschema, oschema)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    81
            if rschema.final:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    82
                if rschema.meta or sschema.is_metadata(rschema) \
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    83
                        or oschema.type in ('Password', 'Bytes'):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    84
                    section = 'hidden'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    85
                else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    86
                    section = 'attributes'
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    87
            else:
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    88
                if rdef.role_cardinality(role) in '1+':
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    89
                    section = 'attributes'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    90
                elif rdef.composite == neg_role(role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    91
                    section = 'relations'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    92
                else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    93
                    section = 'sideboxes'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    94
            self.tag_relation((sschema, rschema, oschema, role), section)
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    95
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    96
primaryview_section = PrimaryViewSectionRelationTags()
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    97
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    98
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    99
class DisplayCtrlRelationTags(NoTargetRelationTagsDict):
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   100
    """primary view display controller configuration"""
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   101
    __regid__ = 'primaryview_display_ctrl'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   102
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   103
    def __init__(self, *args, **kwargs):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   104
        super(DisplayCtrlRelationTags, self).__init__(*args, **kwargs)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   105
        self.counter = 0
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   106
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   107
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   108
        if role == 'subject':
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   109
            oschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   110
        else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   111
            sschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   112
        self.counter += 1
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   113
        self.setdefault((sschema, rschema, oschema, role),
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   114
                        'order',
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   115
                        self.counter)
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   116
9341
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   117
    def set_fields_order(self, etype, relations):
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   118
        """specify the field order in `etype` primary view.
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   119
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   120
        :param etype: the entity type as a string
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   121
        :param attrs: the ordered list of attribute names (or relations)
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   122
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   123
        `attrs` can be strings or 2-tuples (relname, role_of_etype_in_the_rel)
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   124
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   125
        Unspecified fields will be displayed after specified ones, their
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   126
        order being consistent with the schema definition.
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   127
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   128
        Examples:
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   129
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   130
        .. sourcecode:: python
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   131
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   132
          from cubicweb.web.views.uicfg import primaryview_display_ctrl as pvdc
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   133
          pvdc.set_fields_order('CWUser', ('firstname', ('in_group', 'subject'),
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   134
                                           'surname', 'login'))
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   135
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   136
        """
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   137
        for index, relation in enumerate(relations):
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   138
            if not isinstance(relation, tuple):
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   139
                relation = (relation, 'subject')
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   140
            rtype, role = relation
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   141
            if role == 'subject':
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   142
                self.tag_subject_of((etype, rtype, '*'), {'order': index})
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   143
            else:
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   144
                self.tag_object_of((etype, rtype, '*'), {'order': index})
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   145
099a3a33eaaa [uicfg] give a set_fields_order method to the primary view display control
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8696
diff changeset
   146
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   147
primaryview_display_ctrl = DisplayCtrlRelationTags()
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   148
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   149
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   150
# index view configuration ####################################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   151
# entity type section in the index/manage page. May be one of
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   152
# * 'application'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   153
# * 'system'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   154
# * 'schema'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   155
# * 'hidden'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   156
# * 'subobject' (not displayed by default)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   157
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   158
class InitializableDict(dict): # XXX not a rtag. Turn into an appobject?
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   159
    def __init__(self, *args, **kwargs):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   160
        super(InitializableDict, self).__init__(*args, **kwargs)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   161
        self.__defaults = dict(self)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   162
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   163
    def init(self, schema, check=True):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   164
        self.update(self.__defaults)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   165
        for eschema in schema.entities():
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   166
            if eschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   167
                continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   168
            if eschema.schema_entity():
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   169
                self.setdefault(eschema, 'schema')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   170
            elif eschema in INTERNAL_TYPES or eschema in WORKFLOW_TYPES:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   171
                self.setdefault(eschema, 'system')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   172
            elif eschema.is_subobject(strict=True):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   173
                self.setdefault(eschema, 'subobject')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   174
            else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   175
                self.setdefault(eschema, 'application')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   176
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   177
indexview_etype_section = InitializableDict(
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   178
    EmailAddress='subobject',
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   179
    Bookmark='system',
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   180
    # entity types in the 'system' table by default (managers only)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   181
    CWUser='system', CWGroup='system',
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   182
    )
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   183
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   184
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   185
# autoform.AutomaticEntityForm configuration ##################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   186
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   187
def _formsections_as_dict(formsections):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   188
    result = {}
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   189
    for formsection in formsections:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   190
        formtype, section = formsection.split('_', 1)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   191
        result[formtype] = section
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   192
    return result
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   193
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   194
def _card_and_comp(sschema, rschema, oschema, role):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   195
    rdef = rschema.rdef(sschema, oschema)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   196
    if role == 'subject':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   197
        card = rdef.cardinality[0]
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   198
        composed = not rschema.final and rdef.composite == 'object'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   199
    else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   200
        card = rdef.cardinality[1]
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   201
        composed = not rschema.final and rdef.composite == 'subject'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   202
    return card, composed
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   203
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   204
class AutoformSectionRelationTags(RelationTagsSet):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   205
    """autoform relations'section"""
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   206
    __regid__ = 'autoform_section'
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   207
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   208
    _allowed_form_types = ('main', 'inlined', 'muledit')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   209
    _allowed_values = {'main': ('attributes', 'inlined', 'relations',
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   210
                                'metadata', 'hidden'),
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   211
                       'inlined': ('attributes', 'inlined', 'hidden'),
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   212
                       'muledit': ('attributes', 'hidden'),
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   213
                       }
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   214
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   215
    def init(self, schema, check=True):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   216
        super(AutoformSectionRelationTags, self).init(schema, check)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   217
        self.apply(schema, self._initfunc_step2)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   218
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   219
    def _init(self, sschema, rschema, oschema, role):
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   220
        formsections = self.init_get(sschema, rschema, oschema, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   221
        if formsections is None:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   222
            formsections = self.tag_container_cls()
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   223
        if not any(tag.startswith('inlined') for tag in formsections):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   224
            if not rschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   225
                negsects = self.init_get(sschema, rschema, oschema, neg_role(role))
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   226
                if 'main_inlined' in negsects:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   227
                    formsections.add('inlined_hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   228
        key = _ensure_str_key( (sschema, rschema, oschema, role) )
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   229
        self._tagdefs[key] = formsections
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   230
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   231
    def _initfunc_step2(self, sschema, rschema, oschema, role):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   232
        formsections = self.get(sschema, rschema, oschema, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   233
        sectdict = _formsections_as_dict(formsections)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   234
        if rschema in META_RTYPES:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   235
            sectdict.setdefault('main', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   236
            sectdict.setdefault('muledit', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   237
            sectdict.setdefault('inlined', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   238
        elif role == 'subject' and rschema in sschema.meta_attributes():
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   239
            # meta attribute, usually embeded by the described attribute's field
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   240
            # (eg RichTextField, FileField...)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   241
            sectdict.setdefault('main', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   242
            sectdict.setdefault('muledit', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   243
            sectdict.setdefault('inlined', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   244
        # ensure we have a tag for each form type
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   245
        if not 'main' in sectdict:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   246
            if not rschema.final and (
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   247
                sectdict.get('inlined') == 'attributes' or
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   248
                'inlined_attributes' in self.init_get(sschema, rschema, oschema,
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   249
                                                      neg_role(role))):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   250
                sectdict['main'] = 'hidden'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   251
            elif sschema.is_metadata(rschema):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   252
                sectdict['main'] = 'metadata'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   253
            else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   254
                card, composed = _card_and_comp(sschema, rschema, oschema, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   255
                if card in '1+':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   256
                    sectdict['main'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   257
                    if not 'muledit' in sectdict:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   258
                        sectdict['muledit'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   259
                elif rschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   260
                    sectdict['main'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   261
                else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   262
                    sectdict['main'] = 'relations'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   263
        if not 'muledit' in sectdict:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   264
            sectdict['muledit'] = 'hidden'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   265
            if sectdict['main'] == 'attributes':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   266
                card, composed = _card_and_comp(sschema, rschema, oschema, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   267
                if card in '1+' and not composed:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   268
                    sectdict['muledit'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   269
        if not 'inlined' in sectdict:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   270
            sectdict['inlined'] = sectdict['main']
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   271
        # recompute formsections and set it to avoid recomputing
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10612
diff changeset
   272
        for formtype, section in sectdict.items():
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   273
            formsections.add('%s_%s' % (formtype, section))
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   274
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   275
    def tag_relation(self, key, formtype, section):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   276
        if isinstance(formtype, tuple):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   277
            for ftype in formtype:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   278
                self.tag_relation(key, ftype, section)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   279
            return
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   280
        assert formtype in self._allowed_form_types, \
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   281
               'formtype should be in (%s), not %s' % (
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   282
            ','.join(self._allowed_form_types), formtype)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   283
        assert section in self._allowed_values[formtype], \
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   284
               'section for %s should be in (%s), not %s' % (
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   285
            formtype, ','.join(self._allowed_values[formtype]), section)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   286
        rtags = self._tagdefs.setdefault(_ensure_str_key(key),
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   287
                                         self.tag_container_cls())
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   288
        # remove previous section for this form type if any
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   289
        if rtags:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   290
            for tag in rtags.copy():
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   291
                if tag.startswith(formtype):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   292
                    rtags.remove(tag)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   293
        rtags.add('%s_%s' % (formtype, section))
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   294
        return rtags
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   295
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   296
    def init_get(self, stype, rtype, otype, tagged):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   297
        key = (stype, rtype, otype, tagged)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   298
        rtags = {}
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   299
        for key in self._get_keys(stype, rtype, otype, tagged):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   300
            tags = self._tagdefs.get(key, ())
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   301
            for tag in tags:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   302
                assert '_' in tag, (tag, tags)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   303
                section, value = tag.split('_', 1)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   304
                rtags[section] = value
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   305
        cls = self.tag_container_cls
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   306
        rtags = cls('_'.join([section,value])
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10612
diff changeset
   307
                    for section,value in rtags.items())
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   308
        return rtags
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   309
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   310
    def get(self, *key):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   311
        # overriden to avoid recomputing done in parent classes
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   312
        return self._tagdefs.get(key, ())
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   313
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   314
    def relations_by_section(self, entity, formtype, section, permission,
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   315
                             strict=False):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   316
        """return a list of (relation schema, target schemas, role) for the
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   317
        given entity matching categories and permission.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   318
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   319
        `strict`:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   320
          bool telling if having local role is enough (strict = False) or not
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   321
        """
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   322
        tag = '%s_%s' % (formtype, section)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   323
        eschema  = entity.e_schema
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   324
        cw = entity._cw
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   325
        permsoverrides = cw.vreg['uicfg'].select('autoform_permissions_overrides', cw, entity=entity)
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   326
        if entity.has_eid():
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   327
            eid = entity.eid
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   328
        else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   329
            eid = None
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   330
            strict = False
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   331
        if permission == 'update':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   332
            assert section in ('attributes', 'metadata', 'hidden')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   333
            relpermission = 'add'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   334
        else:
9976
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9341
diff changeset
   335
            assert section not in ('metadata', 'hidden')
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   336
            relpermission = permission
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   337
        for rschema, targetschemas, role in eschema.relation_definitions(True):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   338
            _targetschemas = []
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   339
            for tschema in targetschemas:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   340
                # check section's tag first, potentially lower cost than
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   341
                # checking permission which may imply rql queries
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   342
                if not tag in self.etype_get(eschema, rschema, role, tschema):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   343
                    continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   344
                rdef = rschema.role_rdef(eschema, tschema, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   345
                if rschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   346
                    if not rdef.has_perm(cw, permission, eid=eid,
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   347
                                         creating=eid is None):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   348
                        continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   349
                elif strict or not rdef.has_local_role(relpermission):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   350
                    if role == 'subject':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   351
                        if not rdef.has_perm(cw, relpermission, fromeid=eid):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   352
                            continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   353
                    elif role == 'object':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   354
                        if not rdef.has_perm(cw, relpermission, toeid=eid):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   355
                            continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   356
                _targetschemas.append(tschema)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   357
            if not _targetschemas:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   358
                continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   359
            targetschemas = _targetschemas
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   360
            rdef = eschema.rdef(rschema, role=role, targettype=targetschemas[0])
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   361
            # XXX tag allowing to hijack the permission machinery when
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   362
            # permission is not verifiable until the entity is actually
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   363
            # created...
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   364
            if eid is None and '%s_on_new' % permission in permsoverrides.etype_get(eschema, rschema, role):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   365
                yield (rschema, targetschemas, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   366
                continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   367
            if not rschema.final and role == 'subject':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   368
                # on relation with cardinality 1 or ?, we need delete perm as well
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   369
                # if the relation is already set
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   370
                if (relpermission == 'add'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   371
                    and rdef.role_cardinality(role) in '1?'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   372
                    and eid and entity.related(rschema.type, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   373
                    and not rdef.has_perm(cw, 'delete', fromeid=eid,
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   374
                                          toeid=entity.related(rschema.type, role)[0][0])):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   375
                    continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   376
            elif role == 'object':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   377
                # on relation with cardinality 1 or ?, we need delete perm as well
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   378
                # if the relation is already set
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   379
                if (relpermission == 'add'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   380
                    and rdef.role_cardinality(role) in '1?'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   381
                    and eid and entity.related(rschema.type, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   382
                    and not rdef.has_perm(cw, 'delete', toeid=eid,
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   383
                                          fromeid=entity.related(rschema.type, role)[0][0])):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   384
                    continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   385
            yield (rschema, targetschemas, role)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   386
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   387
    def hide_field(self, etype, attr, desttype='*', formtype='main'):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   388
        """hide `attr` in `etype` forms.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   389
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   390
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   391
        :param attr: the name of the attribute or relation to hide
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   392
        :param formtype: which form will be affected ('main', 'inlined', etc.),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   393
         *main* by default.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   394
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   395
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_rel)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   396
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   397
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   398
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   399
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   400
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   401
          from cubicweb.web.views.uicfg import autoform_section as afs
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   402
          afs.hide_field('CWUser', 'login')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   403
          afs.hide_field('*', 'name')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   404
          afs.hide_field('CWUser', 'use_email', formtype='inlined')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   405
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   406
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   407
        self._tag_etype_attr(etype, attr, desttype,
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   408
                             formtype=formtype, section='hidden')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   409
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   410
    def hide_fields(self, etype, attrs, formtype='main'):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   411
        """simple for-loop wrapper around :func:`hide_field`.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   412
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   413
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   414
        :param attrs: the ordered list of attribute names (or relations)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   415
        :param formtype: which form will be affected ('main', 'inlined', etc.),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   416
         *main* by default.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   417
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   418
        `attrs` can be strings or 2-tuples (relname, role_of_etype_in_the_rel)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   419
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   420
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   421
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   422
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   423
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   424
          from cubicweb.web.views.uicfg import autoform_section as afs
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   425
          afs.hide_fields('CWUser', ('login', ('use_email', 'subject')),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   426
                          formtype='inlined')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   427
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   428
        for attr in attrs:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   429
            self.hide_field(etype, attr, formtype=formtype)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   430
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   431
    def edit_inline(self, etype, attr, desttype='*', formtype=('main', 'inlined')):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   432
        """edit `attr` with and inlined form.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   433
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   434
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   435
        :param attr: the name of the attribute or relation
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   436
        :param desttype: the destination type(s) concerned, default is everything
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   437
        :param formtype: which form will be affected ('main', 'inlined', etc.),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   438
          *main* and *inlined* by default.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   439
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   440
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   441
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   442
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   443
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   444
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   445
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   446
          from cubicweb.web.views.uicfg import autoform_section as afs
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   447
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   448
          afs.edit_inline('*', 'use_email')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   449
      """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   450
        self._tag_etype_attr(etype, attr, desttype, formtype=formtype,
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   451
                             section='inlined')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   452
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   453
    def edit_as_attr(self, etype, attr, desttype='*', formtype=('main', 'muledit')):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   454
        """make `attr` appear in the *attributes* section of `etype` form.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   455
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   456
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   457
        :param attr: the name of the attribute or relation
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   458
        :param desttype: the destination type(s) concerned, default is everything
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   459
        :param formtype: which form will be affected ('main', 'inlined', etc.),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   460
          *main* and *muledit* by default.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   461
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   462
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   463
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   464
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   465
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   466
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   467
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   468
          from cubicweb.web.views.uicfg import autoform_section as afs
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   469
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   470
          afs.edit_as_attr('CWUser', 'in_group')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   471
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   472
        self._tag_etype_attr(etype, attr, desttype,
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   473
                             formtype=formtype, section='attributes')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   474
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   475
    def set_muledit_editable(self, etype, attrs):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   476
        """make `attrs` appear in muledit form of `etype`.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   477
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   478
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   479
        :param attrs: the ordered list of attribute names (or relations)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   480
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   481
        `attrs` can be strings or 2-tuples (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   482
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   483
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   484
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   485
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   486
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   487
          from cubicweb.web.views.uicfg import autoform_section as afs
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   488
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   489
          afs.set_muledit_editable('CWUser', ('firstname', 'surname', 'in_group'))
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   490
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   491
        for attr in attrs:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   492
            self.edit_as_attr(self, etype, attr, formtype='muledit')
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   493
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   494
autoform_section = AutoformSectionRelationTags()
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   495
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   496
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   497
# relations'field class
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   498
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   499
class AutoformFieldTags(RelationTags):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   500
    __regid__ = 'autoform_field'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   501
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   502
    def set_field(self, etype, attr, field):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   503
        """sets the `attr` field of `etype`.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   504
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   505
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   506
        :param attr: the name of the attribute or relation
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   507
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   508
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   509
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   510
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   511
        self._tag_etype_attr(etype, attr, '*', field)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   512
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   513
autoform_field = AutoformFieldTags()
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   514
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   515
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   516
# relations'field explicit kwargs (given to field's __init__)
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   517
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   518
class AutoformFieldKwargsTags(RelationTagsDict):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   519
    __regid__ = 'autoform_field_kwargs'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   520
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   521
    def set_fields_order(self, etype, attrs):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   522
        """specify the field order in `etype` main edition form.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   523
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   524
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   525
        :param attrs: the ordered list of attribute names (or relations)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   526
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   527
        `attrs` can be strings or 2-tuples (relname, role_of_etype_in_the_rel)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   528
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   529
        Unspecified fields will be displayed after specified ones, their
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   530
        order being consistent with the schema definition.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   531
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   532
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   533
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   534
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   535
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   536
          from cubicweb.web.views.uicfg import autoform_field_kwargs as affk
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   537
          affk.set_fields_order('CWUser', ('firstname', 'surname', 'login'))
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   538
          affk.set_fields_order('CWUser', ('firstname', ('in_group', 'subject'),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   539
                                'surname', 'login'))
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   540
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   541
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   542
        for index, attr in enumerate(attrs):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   543
            self._tag_etype_attr(etype, attr, '*', {'order': index})
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   544
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   545
    def set_field_kwargs(self, etype, attr, **kwargs):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   546
        """tag `attr` field of `etype` with additional named paremeters.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   547
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   548
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   549
        :param attr: the name of the attribute or relation
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   550
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   551
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   552
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   553
        Examples:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   554
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   555
        .. sourcecode:: python
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   556
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   557
          from cubicweb.web.views.uicfg import autoform_field_kwargs as affk
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   558
          affk.set_field_kwargs('Person', 'works_for', widget=fwdgs.AutoCompletionWidget())
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   559
          affk.set_field_kwargs('CWUser', 'login', label=_('login or email address'),
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   560
                                widget=fwdgs.TextInput(attrs={'size': 30}))
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   561
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   562
        self._tag_etype_attr(etype, attr, '*', kwargs)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   563
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   564
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   565
autoform_field_kwargs = AutoformFieldKwargsTags()
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   566
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   567
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   568
# set of tags of the form <action>_on_new on relations. <action> is a
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   569
# schema action (add/update/delete/read), and when such a tag is found
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   570
# permissions checking is by-passed and supposed to be ok
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   571
class AutoFormPermissionsOverrides(RelationTagsSet):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   572
    __regid__ = 'autoform_permissions_overrides'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   573
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   574
autoform_permissions_overrides = AutoFormPermissionsOverrides()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   575
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   576
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   577
class ReleditTags(NoTargetRelationTagsDict):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   578
    """Associate to relation a dictionary to control `reledit` (e.g. edition of
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   579
    attributes / relations from within views).
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   580
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   581
    Possible keys and associated values are:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   582
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   583
    * `novalue_label`, alternative default value (shown when there is no value).
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   584
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   585
    * `novalue_include_rtype`, when `novalue_label` is not specified, this boolean
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   586
      flag control wether the generated default value should contains the
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   587
      relation label or not. Will be the opposite of the `showlabel` value found
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   588
      in the `primaryview_display_ctrl` rtag by default.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   589
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   590
    * `reload`, boolean, eid (to reload to) or function taking subject and
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   591
      returning bool/eid. This is useful when editing a relation (or attribute)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   592
      that impacts the url or another parts of the current displayed
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   593
      page. Defaults to False.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   594
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   595
    * `rvid`, alternative view id (as str) for relation or composite edition.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   596
      Default is 'autolimited'.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   597
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   598
    * `edit_target`, may be either 'rtype' (to edit the relation) or 'related'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   599
      (to edit the related entity).  This controls whether to edit the relation
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   600
      or the target entity of the relation.  Currently only one-to-one relations
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   601
      support target entity edition. By default, the 'related' option is taken
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   602
      whenever the relation is composite.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   603
    """
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   604
    __regid__ = 'reledit'
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   605
    _keys = frozenset('novalue_label novalue_include_rtype reload rvid edit_target'.split())
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   606
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   607
    def tag_relation(self, key, tag):
8696
0bb18407c053 [toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8667
diff changeset
   608
        for tagkey in tag:
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   609
            assert tagkey in self._keys, 'tag %r not in accepted tags: %r' % (tag, self._keys)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   610
        return super(ReleditTags, self).tag_relation(key, tag)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   611
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   612
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   613
        values = self.get(sschema, rschema, oschema, role)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   614
        if not rschema.final:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   615
            composite = rschema.rdef(sschema, oschema).composite == role
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   616
            if role == 'subject':
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   617
                oschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   618
            else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   619
                sschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   620
            edittarget = values.get('edit_target')
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   621
            if edittarget not in (None, 'rtype', 'related'):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   622
                self.warning('reledit: wrong value for edit_target on relation %s: %s',
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   623
                             rschema, edittarget)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   624
                edittarget = None
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   625
            if not edittarget:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   626
                edittarget = 'related' if composite else 'rtype'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   627
                self.tag_relation((sschema, rschema, oschema, role),
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   628
                                  {'edit_target': edittarget})
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   629
        if not 'novalue_include_rtype' in values:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   630
            showlabel = primaryview_display_ctrl.get(
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   631
                sschema, rschema, oschema, role).get('showlabel', True)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   632
            self.tag_relation((sschema, rschema, oschema, role),
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   633
                              {'novalue_include_rtype': not showlabel})
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   634
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   635
reledit_ctrl = ReleditTags()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   636
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   637
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   638
# boxes.EditBox configuration #################################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   639
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   640
# 'link' / 'create' relation tags, used to control the "add entity" submenu
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   641
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   642
class ActionBoxUicfg(RelationTagsBool):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   643
    __regid__ = 'actionbox_appearsin_addmenu'
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   644
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   645
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   646
        if self.get(sschema, rschema, oschema, role) is None:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   647
            if rschema in META_RTYPES:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   648
                self.tag_relation((sschema, rschema, oschema, role), False)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   649
                return
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   650
            rdef = rschema.rdef(sschema, oschema)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   651
            if not rdef.role_cardinality(role) in '?1' and rdef.composite == role:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   652
                self.tag_relation((sschema, rschema, oschema, role), True)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   653
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   654
    def _tag_etype_attr(self, etype, attr, desttype='*', *args, **kwargs):
10612
84468b90e9c1 [py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9984
diff changeset
   655
        if isinstance(attr, string_types):
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   656
            attr, role = attr, 'subject'
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   657
        else:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   658
            attr, role = attr
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   659
        if role == 'subject':
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   660
            self.tag_subject_of((etype, attr, desttype), *args, **kwargs)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   661
        else:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   662
            self.tag_object_of((desttype, attr, etype), *args, **kwargs)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   663
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   664
    def append_to_addmenu(self, etype, attr, createdtype='*'):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   665
        """adds `attr` in the actions box *addrelated* submenu of `etype`.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   666
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   667
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   668
        :param attr: the name of the attribute or relation to hide
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   669
        :param createdtype: the target type of the relation (optional, defaults to '*' (all possible types))
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   670
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   671
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   672
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   673
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   674
        self._tag_etype_attr(etype, attr, createdtype, True)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   675
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   676
    def remove_from_addmenu(self, etype, attr, createdtype='*'):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   677
        """removes `attr` from the actions box *addrelated* submenu of `etype`.
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   678
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   679
        :param etype: the entity type as a string
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   680
        :param attr: the name of the attribute or relation to hide
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   681
        :param createdtype: the target type of the relation (optional, defaults to '*' (all possible types))
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   682
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   683
        `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   684
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   685
        self._tag_etype_attr(etype, attr, createdtype, False)
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   686
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   687
actionbox_appearsin_addmenu = ActionBoxUicfg()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   688
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   689
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   690
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   691
def registration_callback(vreg):
10663
54b8a1f249fb [py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10662
diff changeset
   692
    vreg.register_all(globals().values(), __name__)
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   693
    indexview_etype_section.init(vreg.schema)