web/views/uicfg.py
author Rémi Cardona <remi.cardona@logilab.fr>
Tue, 10 Feb 2015 14:38:25 +0100
changeset 10311 4e9dcca71fad
parent 9984 793377697c81
child 10612 84468b90e9c1
permissions -rw-r--r--
[views] Fix 'gc' view to use 'repo_gc_stats' service
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
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    60
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
    61
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
    62
                            RelationTagsDict, NoTargetRelationTagsDict,
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    63
                            _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
    64
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
    65
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    66
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    67
# primary view configuration ##################################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    68
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    69
class PrimaryViewSectionRelationTags(RelationTags):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    70
    """primary view section configuration"""
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    71
    __regid__ = 'primaryview_section'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    72
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    73
    _allowed_values = frozenset(('attributes', 'relations',
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    74
                                 'sideboxes', 'hidden'))
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    75
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    76
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    77
        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
    78
            rdef = rschema.rdef(sschema, oschema)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    79
            if rschema.final:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    80
                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
    81
                        or oschema.type in ('Password', 'Bytes'):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    82
                    section = 'hidden'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    83
                else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    84
                    section = 'attributes'
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    85
            else:
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    86
                if rdef.role_cardinality(role) in '1+':
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    87
                    section = 'attributes'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    88
                elif rdef.composite == neg_role(role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    89
                    section = 'relations'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    90
                else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    91
                    section = 'sideboxes'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    92
            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
    93
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    94
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
    95
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    96
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    97
class DisplayCtrlRelationTags(NoTargetRelationTagsDict):
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    98
    """primary view display controller configuration"""
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
    99
    __regid__ = 'primaryview_display_ctrl'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   100
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   101
    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
   102
        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
   103
        self.counter = 0
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   104
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   105
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   106
        if role == 'subject':
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   107
            oschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   108
        else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   109
            sschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   110
        self.counter += 1
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   111
        self.setdefault((sschema, rschema, oschema, role),
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   112
                        'order',
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   113
                        self.counter)
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   114
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
   115
    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
   116
        """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
   117
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
        :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
   119
        :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
   120
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
        `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
   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
        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
   124
        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
   125
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
        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
   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
        .. 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
   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
          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
   131
          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
   132
                                           '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
   133
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
        """
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
        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
   136
            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
   137
                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
   138
            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
   139
            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
   140
                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
   141
            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
   142
                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
   143
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
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   145
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
   146
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   147
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   148
# index view configuration ####################################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   149
# 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
   150
# * 'application'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   151
# * 'system'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   152
# * 'schema'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   153
# * 'hidden'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   154
# * '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
   155
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   156
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
   157
    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
   158
        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
   159
        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
   160
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   161
    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
   162
        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
   163
        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
   164
            if eschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   165
                continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   166
            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
   167
                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
   168
            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
   169
                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
   170
            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
   171
                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
   172
            else:
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, 'application')
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   174
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   175
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
   176
    EmailAddress='subobject',
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   177
    Bookmark='system',
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   178
    # 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
   179
    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
   180
    )
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   181
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   182
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   183
# autoform.AutomaticEntityForm configuration ##################################
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   184
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   185
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
   186
    result = {}
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   187
    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
   188
        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
   189
        result[formtype] = section
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   190
    return result
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   191
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   192
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
   193
    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
   194
    if role == 'subject':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   195
        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
   196
        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
   197
    else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   198
        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
   199
        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
   200
    return card, composed
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   201
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   202
class AutoformSectionRelationTags(RelationTagsSet):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   203
    """autoform relations'section"""
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   204
    __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
   205
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   206
    _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
   207
    _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
   208
                                'metadata', 'hidden'),
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   209
                       '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
   210
                       'muledit': ('attributes', 'hidden'),
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   211
                       }
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   212
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   213
    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
   214
        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
   215
        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
   216
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   217
    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
   218
        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
   219
        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
   220
            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
   221
        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
   222
            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
   223
                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
   224
                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
   225
                    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
   226
        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
   227
        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
   228
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   229
    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
   230
        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
   231
        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
   232
        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
   233
            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
   234
            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
   235
            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
   236
        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
   237
            # 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
   238
            # (eg RichTextField, FileField...)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   239
            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
   240
            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
   241
            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
   242
        # 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
   243
        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
   244
            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
   245
                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
   246
                '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
   247
                                                      neg_role(role))):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   248
                sectdict['main'] = 'hidden'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   249
            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
   250
                sectdict['main'] = 'metadata'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   251
            else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   252
                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
   253
                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
   254
                    sectdict['main'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   255
                    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
   256
                        sectdict['muledit'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   257
                elif rschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   258
                    sectdict['main'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   259
                else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   260
                    sectdict['main'] = 'relations'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   261
        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
   262
            sectdict['muledit'] = 'hidden'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   263
            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
   264
                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
   265
                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
   266
                    sectdict['muledit'] = 'attributes'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   267
        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
   268
            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
   269
        # recompute formsections and set it to avoid recomputing
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   270
        for formtype, section in sectdict.iteritems():
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   271
            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
   272
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   273
    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
   274
        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
   275
            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
   276
                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
   277
            return
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   278
        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
   279
               '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
   280
            ','.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
   281
        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
   282
               '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
   283
            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
   284
        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
   285
                                         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
   286
        # 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
   287
        if rtags:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   288
            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
   289
                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
   290
                    rtags.remove(tag)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   291
        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
   292
        return rtags
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   293
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   294
    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
   295
        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
   296
        rtags = {}
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   297
        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
   298
            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
   299
            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
   300
                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
   301
                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
   302
                rtags[section] = value
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   303
        cls = self.tag_container_cls
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   304
        rtags = cls('_'.join([section,value])
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   305
                    for section,value in rtags.iteritems())
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   306
        return rtags
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   307
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   308
    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
   309
        # 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
   310
        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
   311
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   312
    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
   313
                             strict=False):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   314
        """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
   315
        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
   316
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   317
        `strict`:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   318
          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
   319
        """
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   320
        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
   321
        eschema  = entity.e_schema
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   322
        cw = entity._cw
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   323
        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
   324
        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
   325
            eid = entity.eid
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   326
        else:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   327
            eid = None
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   328
            strict = False
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   329
        if permission == 'update':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   330
            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
   331
            relpermission = 'add'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   332
        else:
9976
457efde98629 [views] Display attributes in entity creation form based on "add" permission
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9341
diff changeset
   333
            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
   334
            relpermission = permission
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   335
        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
   336
            _targetschemas = []
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   337
            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
   338
                # 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
   339
                # 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
   340
                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
   341
                    continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   342
                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
   343
                if rschema.final:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   344
                    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
   345
                                         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
   346
                        continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   347
                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
   348
                    if role == 'subject':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   349
                        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
   350
                            continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   351
                    elif role == 'object':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   352
                        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
   353
                            continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   354
                _targetschemas.append(tschema)
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   355
            if not _targetschemas:
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   356
                continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   357
            targetschemas = _targetschemas
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   358
            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
   359
            # 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
   360
            # 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
   361
            # created...
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   362
            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
   363
                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
   364
                continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   365
            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
   366
                # 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
   367
                # 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
   368
                if (relpermission == 'add'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   369
                    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
   370
                    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
   371
                    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
   372
                                          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
   373
                    continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   374
            elif role == 'object':
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   375
                # 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
   376
                # 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
   377
                if (relpermission == 'add'
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   378
                    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
   379
                    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
   380
                    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
   381
                                          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
   382
                    continue
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   383
            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
   384
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   385
    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
   386
        """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
   387
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   388
        :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
   389
        :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
   390
        :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
   391
         *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
   392
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   393
        `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
   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
        Examples:
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
        .. 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
   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
          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
   400
          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
   401
          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
   402
          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
   403
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   404
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   405
        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
   406
                             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
   407
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   408
    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
   409
        """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
   410
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   411
        :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
   412
        :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
   413
        :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
   414
         *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
   415
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   416
        `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
   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
        Examples:
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
        .. 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
   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
          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
   423
          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
   424
                          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
   425
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   426
        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
   427
            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
   428
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   429
    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
   430
        """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
   431
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   432
        :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
   433
        :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
   434
        :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
   435
        :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
   436
          *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
   437
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   438
        `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
   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
        Examples:
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
        .. 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
   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
          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
   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
          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
   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
        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
   449
                             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
   450
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   451
    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
   452
        """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
   453
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   454
        :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
   455
        :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
   456
        :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
   457
        :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
   458
          *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
   459
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   460
        `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
   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
        Examples:
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
        .. 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
   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
          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
   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
          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
   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
        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
   471
                             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
   472
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   473
    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
   474
        """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
   475
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   476
        :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
   477
        :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
   478
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   479
        `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
   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
        Examples:
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
        .. 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
   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
          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
   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
          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
   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
        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
   490
            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
   491
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   492
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
   493
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   494
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   495
# 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
   496
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   497
class AutoformFieldTags(RelationTags):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   498
    __regid__ = 'autoform_field'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   499
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   500
    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
   501
        """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
   502
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   503
        :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
   504
        :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
   505
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   506
        `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
   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
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   509
        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
   510
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   511
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
   512
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   513
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   514
# 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
   515
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   516
class AutoformFieldKwargsTags(RelationTagsDict):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   517
    __regid__ = 'autoform_field_kwargs'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   518
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   519
    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
   520
        """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
   521
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   522
        :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
   523
        :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
   524
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   525
        `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
   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
        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
   528
        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
   529
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   530
        Examples:
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
        .. 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
   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
          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
   535
          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
   536
          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
   537
                                '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
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   539
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   540
        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
   541
            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
   542
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   543
    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
   544
        """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
   545
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   546
        :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
   547
        :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
   548
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   549
        `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
   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
        Examples:
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
        .. 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
   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
          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
   556
          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
   557
          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
   558
                                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
   559
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   560
        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
   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
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   563
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
   564
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   565
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   566
# 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
   567
# 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
   568
# 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
   569
class AutoFormPermissionsOverrides(RelationTagsSet):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   570
    __regid__ = 'autoform_permissions_overrides'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   571
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   572
autoform_permissions_overrides = AutoFormPermissionsOverrides()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   573
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   574
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   575
class ReleditTags(NoTargetRelationTagsDict):
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   576
    """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
   577
    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
   578
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   579
    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
   580
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   581
    * `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
   582
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   583
    * `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
   584
      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
   585
      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
   586
      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
   587
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   588
    * `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
   589
      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
   590
      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
   591
      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
   592
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   593
    * `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
   594
      Default is 'autolimited'.
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   595
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   596
    * `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
   597
      (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
   598
      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
   599
      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
   600
      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
   601
    """
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   602
    __regid__ = 'reledit'
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   603
    _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
   604
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   605
    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
   606
        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
   607
            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
   608
        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
   609
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   610
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   611
        values = self.get(sschema, rschema, oschema, role)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   612
        if not rschema.final:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   613
            composite = rschema.rdef(sschema, oschema).composite == role
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   614
            if role == 'subject':
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   615
                oschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   616
            else:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   617
                sschema = '*'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   618
            edittarget = values.get('edit_target')
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   619
            if edittarget not in (None, 'rtype', 'related'):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   620
                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
   621
                             rschema, edittarget)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   622
                edittarget = None
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   623
            if not edittarget:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   624
                edittarget = 'related' if composite else 'rtype'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   625
                self.tag_relation((sschema, rschema, oschema, role),
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   626
                                  {'edit_target': edittarget})
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   627
        if not 'novalue_include_rtype' in values:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   628
            showlabel = primaryview_display_ctrl.get(
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   629
                sschema, rschema, oschema, role).get('showlabel', True)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   630
            self.tag_relation((sschema, rschema, oschema, role),
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   631
                              {'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
   632
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   633
reledit_ctrl = ReleditTags()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   634
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   635
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   636
# boxes.EditBox configuration #################################################
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
# '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
   639
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   640
class ActionBoxUicfg(RelationTagsBool):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   641
    __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
   642
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   643
    def _init(self, sschema, rschema, oschema, role):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   644
        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
   645
            if rschema in META_RTYPES:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   646
                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
   647
                return
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   648
            rdef = rschema.rdef(sschema, oschema)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   649
            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
   650
                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
   651
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   652
    def _tag_etype_attr(self, 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
   653
        if isinstance(attr, basestring):
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   654
            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
   655
        else:
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
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   657
        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
   658
            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
   659
        else:
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_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
   661
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   662
    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
   663
        """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
   664
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   665
        :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
   666
        :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
   667
        :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
   668
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   669
        `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
   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
        """
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   672
        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
   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
    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
   675
        """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
   676
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   677
        :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
   678
        :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
   679
        :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
   680
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   681
        `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
   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
        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
   684
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   685
actionbox_appearsin_addmenu = ActionBoxUicfg()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   686
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   687
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
def registration_callback(vreg):
8696
0bb18407c053 [toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8667
diff changeset
   690
    vreg.register_all(globals().itervalues(), __name__)
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 8665
diff changeset
   691
    indexview_etype_section.init(vreg.schema)