rtags.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 11 Sep 2014 16:43:20 +0200
changeset 9976 457efde98629
parent 8667 5a394fc419b4
child 10612 84468b90e9c1
permissions -rw-r--r--
[views] Display attributes in entity creation form based on "add" permission Previously, the "update" permission was used. Hence in case the latter is more restrictive that the "add" permission, an user may not be able to set such an attribute, despite she may have "add" permission on it. As a result of the change of permissions action in `editable_attributes` method (add/update depending on whether the entity is being created or modified), the "eid" attribute would have shown up in the edition form. To avoid this, it is moved in the "hidden" section (where it should arguably belong anyways). Closes #4342844.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5314
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
4931
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    18
"""
5314
86e5abbebfaf [doc/book] refresh the autoform section with uicfg content (moved there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4931
diff changeset
    19
A RelationTag object is an object which allows to link a configuration
86e5abbebfaf [doc/book] refresh the autoform section with uicfg content (moved there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4931
diff changeset
    20
information to a relation definition. For instance, the standard
86e5abbebfaf [doc/book] refresh the autoform section with uicfg content (moved there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4931
diff changeset
    21
primary view uses a RelationTag object (uicfg.primaryview_section) to
86e5abbebfaf [doc/book] refresh the autoform section with uicfg content (moved there)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4931
diff changeset
    22
get the section to display relations.
4931
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    23
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    24
.. sourcecode:: python
1152
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    25
4931
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    26
   # display ``entry_of`` relations in the ``relations`` section in the ``BlogEntry`` primary view
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    27
   uicfg.primaryview_section.tag_subject_of(('BlogEntry', 'entry_of', '*'),
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    28
                                             'relations')
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    29
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    30
   # hide every relation ``entry_of`` in the ``Blog`` primary view
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    31
   uicfg.primaryview_section.tag_object_of(('*', 'entry_of', 'Blog'), 'hidden')
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    32
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    33
Three primitives are defined:
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    34
   * ``tag_subject_of`` tag a relation in the subject's context
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    35
   * ``tag_object_of`` tag a relation in the object's context
92c9d0a5dc11 improve documentation for uicfg and rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 4391
diff changeset
    36
   * ``tag_attribute`` shortcut for tag_subject_of
1152
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    37
"""
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    38
__docformat__ = "restructuredtext en"
1148
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
1740
2292ae32c98f warn and drop rtags not in schema, this may be intentional; drop possibility to not specify value for bool rtags
sylvain.thenault@logilab.fr
parents: 1739
diff changeset
    40
import logging
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    41
from warnings import warn
1740
2292ae32c98f warn and drop rtags not in schema, this may be intentional; drop possibility to not specify value for bool rtags
sylvain.thenault@logilab.fr
parents: 1739
diff changeset
    42
2292ae32c98f warn and drop rtags not in schema, this may be intentional; drop possibility to not specify value for bool rtags
sylvain.thenault@logilab.fr
parents: 1739
diff changeset
    43
from logilab.common.logging_ext import set_log_methods
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    44
from logilab.common.registry import RegistrableInstance, yes
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    45
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
    46
def _ensure_str_key(key):
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
    47
    return tuple(str(k) for k in key)
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
    48
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    49
class RegistrableRtags(RegistrableInstance):
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    50
    __registry__ = 'uicfg'
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    51
    __select__ = yes()
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    52
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    53
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    54
class RelationTags(RegistrableRtags):
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    55
    """a tag store for full relation definitions :
1148
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    57
         (subject type, relation type, object type, tagged)
1152
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    58
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    59
    allowing to set tags using wildcard (eg '*') as subject type / object type
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    60
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    61
    This class associates a single tag to each key.
1152
c99ef2a2535c cleanup
sylvain.thenault@logilab.fr
parents: 1148
diff changeset
    62
    """
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
    63
    _allowed_values = None
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    64
    # _init expected to be a method (introduced in 3.17), while _initfunc a
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    65
    # function given as __init__ argument and kept for bw compat
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    66
    _init = _initfunc = None
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    67
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    68
    def __init__(self):
1148
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
        self._tagdefs = {}
1769
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
    70
1528
864ae7c15ef5 other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1451
diff changeset
    71
    def __repr__(self):
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    72
        # find a way to have more infos but keep it readable
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    73
        # (in error messages in case of an ambiguity for instance)
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
    74
        return '%s (%s): %s' % (id(self), self.__regid__, self.__class__)
1528
864ae7c15ef5 other fixlets
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1451
diff changeset
    75
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    76
    # dict compat
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    77
    def __getitem__(self, key):
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    78
        return self.get(*key)
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    79
    __contains__ = __getitem__
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1356
diff changeset
    80
2689
44f041222d0f [autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2369
diff changeset
    81
    def clear(self):
44f041222d0f [autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2369
diff changeset
    82
        self._tagdefs.clear()
44f041222d0f [autoreload] handle uicfg reloading properly with the new event / callback mechanism
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2369
diff changeset
    83
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
    84
    def _get_keys(self, stype, rtype, otype, tagged):
5843
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    85
        keys = []
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    86
        if '*' not in (stype, otype):
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    87
            keys.append(('*', rtype, '*', tagged))
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    88
        if '*' != stype:
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    89
            keys.append(('*', rtype, otype, tagged))
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    90
        if '*' != otype:
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    91
            keys.append((stype, rtype, '*', tagged))
85c4d5334f2c [refactor] refactor rtag keys generations.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 5424
diff changeset
    92
        keys.append((stype, rtype, otype, tagged))
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
    93
        return keys
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1356
diff changeset
    94
1769
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
    95
    def init(self, schema, check=True):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
    96
        # XXX check existing keys against schema
1769
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
    97
        if check:
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
    98
            for (stype, rtype, otype, tagged), value in self._tagdefs.items():
1769
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
    99
                for ertype in (stype, rtype, otype):
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
   100
                    if ertype != '*' and not ertype in schema:
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
   101
                        self.warning('removing rtag %s: %s, %s undefined in schema',
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
   102
                                     (stype, rtype, otype, tagged), value, ertype)
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
   103
                        self.del_rtag(stype, rtype, otype, tagged)
fb91d2b8a441 fix some rtags pb on i18n catalog generation
sylvain.thenault@logilab.fr
parents: 1752
diff changeset
   104
                        break
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
   105
        if self._init is not None:
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
   106
            self.apply(schema, self._init)
4364
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   107
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   108
    def apply(self, schema, func):
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   109
        for eschema in schema.entities():
6899
e592fb8ee27b [rtags] speepup initialization by avoiding to get file entity types relations (useless)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6246
diff changeset
   110
            if eschema.final:
e592fb8ee27b [rtags] speepup initialization by avoiding to get file entity types relations (useless)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6246
diff changeset
   111
                continue
4364
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   112
            for rschema, tschemas, role in eschema.relation_definitions(True):
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   113
                for tschema in tschemas:
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   114
                    if role == 'subject':
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   115
                        sschema, oschema = eschema, tschema
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   116
                    else:
766359c69f2f [uicfg] fix autoform_section rtags initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4339
diff changeset
   117
                        sschema, oschema = tschema, eschema
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
   118
                    func(sschema, rschema, oschema, role)
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   119
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   120
    # rtag declaration api ####################################################
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   121
3473
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   122
    def tag_attribute(self, key, *args, **kwargs):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   123
        key = list(key)
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   124
        key.append('*')
4339
fe93b670343d some fixes so that deprecation warning are properly localized
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   125
        key.append('subject')
fe93b670343d some fixes so that deprecation warning are properly localized
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   126
        self.tag_relation(key, *args, **kwargs)
1548
bd225e776739 new tag_attribute convenience method
sylvain.thenault@logilab.fr
parents: 1533
diff changeset
   127
3473
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   128
    def tag_subject_of(self, key, *args, **kwargs):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   129
        key = list(key)
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   130
        key.append('subject')
3473
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   131
        self.tag_relation(key, *args, **kwargs)
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   132
3473
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   133
    def tag_object_of(self, key, *args, **kwargs):
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   134
        key = list(key)
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   135
        key.append('object')
3473
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   136
        self.tag_relation(key, *args, **kwargs)
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
   137
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   138
    def tag_relation(self, key, tag):
4391
bd8480824e0b ensure we get a correct key
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4364
diff changeset
   139
        assert len(key) == 4, 'bad key: %s' % list(key)
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   140
        if self._allowed_values is not None:
1859
b068abd45a1c nicer error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1849
diff changeset
   141
            assert tag in self._allowed_values, \
b068abd45a1c nicer error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1849
diff changeset
   142
                   '%r is not an allowed tag (should be in %s)' % (
b068abd45a1c nicer error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1849
diff changeset
   143
                tag, self._allowed_values)
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   144
        self._tagdefs[_ensure_str_key(key)] = tag
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   145
        return tag
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
   146
8667
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   147
    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
   148
        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
   149
            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
   150
        else:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   151
            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
   152
        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
   153
            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
   154
        else:
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   155
            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
   156
5a394fc419b4 [web/uihelper,uicfg] transform uihelper functions into uicfg objects methods (closes #2543949)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8666
diff changeset
   157
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   158
    # rtag runtime api ########################################################
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   159
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   160
    def del_rtag(self, *key):
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   161
        del self._tagdefs[key]
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   162
3473
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   163
    def get(self, *key):
d8bc02158efc [rtags] ease overriding
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3472
diff changeset
   164
        for key in reversed(self._get_keys(*key)):
1148
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   165
            try:
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   166
                return self._tagdefs[key]
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   167
            except KeyError:
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   168
                continue
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   169
        return None
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1356
diff changeset
   170
1721
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1548
diff changeset
   171
    def etype_get(self, etype, rtype, role, ttype='*'):
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1548
diff changeset
   172
        if role == 'subject':
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1548
diff changeset
   173
            return self.get(etype, rtype, ttype, role)
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1548
diff changeset
   174
        return self.get(ttype, rtype, etype, role)
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
   175
7083
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6900
diff changeset
   176
    # these are overridden by set_log_methods below
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6900
diff changeset
   177
    # only defining here to prevent pylint from complaining
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6900
diff changeset
   178
    info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
   179
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1356
diff changeset
   180
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
   181
class RelationTagsSet(RelationTags):
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   182
    """This class associates a set of tags to each key.
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   183
    """
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   184
    tag_container_cls = set
1533
bcd4bfff658b update rtags api
sylvain.thenault@logilab.fr
parents: 1528
diff changeset
   185
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   186
    def tag_relation(self, key, tag):
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   187
        rtags = self._tagdefs.setdefault(_ensure_str_key(key),
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   188
                                         self.tag_container_cls())
1148
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   189
        rtags.add(tag)
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   190
        return rtags
1451
982e8616d9a2 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1356
diff changeset
   191
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   192
    def get(self, stype, rtype, otype, tagged):
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   193
        rtags = self.tag_container_cls()
1721
694f6a50e138 final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents: 1548
diff changeset
   194
        for key in self._get_keys(stype, rtype, otype, tagged):
1148
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   195
            try:
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   196
                rtags.update(self._tagdefs[key])
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   197
            except KeyError:
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   198
                continue
55a8238f8f7c keep notion of relation tags, tough with simplier implementation and usage
sylvain.thenault@logilab.fr
parents:
diff changeset
   199
        return rtags
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   200
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   201
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   202
class RelationTagsDict(RelationTagsSet):
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   203
    """This class associates a set of tags to each key."""
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   204
    tag_container_cls = dict
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   205
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   206
    def tag_relation(self, key, tag):
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   207
        key = _ensure_str_key(key)
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   208
        try:
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   209
            rtags = self._tagdefs[key]
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   210
            rtags.update(tag)
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   211
            return rtags
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   212
        except KeyError:
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   213
            self._tagdefs[key] = tag
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   214
            return tag
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   215
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   216
    def setdefault(self, key, tagkey, tagvalue):
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   217
        key = _ensure_str_key(key)
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   218
        try:
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   219
            rtags = self._tagdefs[key]
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   220
            rtags.setdefault(tagkey, tagvalue)
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   221
            return rtags
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   222
        except KeyError:
3472
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   223
            self._tagdefs[key] = {tagkey: tagvalue}
5345570eefc6 [rtags] make internal key order consistent with api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2689
diff changeset
   224
            return self._tagdefs[key]
2369
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   225
5a2b8ed266ca new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   226
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   227
class RelationTagsBool(RelationTags):
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   228
    _allowed_values = frozenset((True, False))
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   229
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1726
diff changeset
   230
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   231
class NoTargetRelationTagsDict(RelationTagsDict):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   232
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   233
    @property
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   234
    def name(self):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   235
        return self.__class__.name
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   236
6900
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   237
    # tag_subject_of / tag_object_of issue warning if '*' is not given as target
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   238
    # type, while tag_relation handle it silently since it may be used during
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   239
    # initialization
6246
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   240
    def tag_subject_of(self, key, tag):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   241
        subj, rtype, obj = key
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   242
        if obj != '*':
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   243
            self.warning('using explict target type in %s.tag_subject_of() '
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   244
                         'has no effect, use (%s, %s, "*") instead of (%s, %s, %s)',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   245
                         self.name, subj, rtype, subj, rtype, obj)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   246
        super(NoTargetRelationTagsDict, self).tag_subject_of((subj, rtype, '*'), tag)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   247
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   248
    def tag_object_of(self, key, tag):
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   249
        subj, rtype, obj = key
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   250
        if subj != '*':
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   251
            self.warning('using explict subject type in %s.tag_object_of() '
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   252
                         'has no effect, use ("*", %s, %s) instead of (%s, %s, %s)',
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   253
                         self.name, rtype, obj, subj, rtype, obj)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   254
        super(NoTargetRelationTagsDict, self).tag_object_of(('*', rtype, obj), tag)
62e25fac41cd [views/reledit] refactor composite handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6240
diff changeset
   255
6900
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   256
    def tag_relation(self, key, tag):
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   257
        if key[-1] == 'subject' and key[-2] != '*':
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   258
            if isinstance(key, tuple):
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   259
                key = list(key)
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   260
            key[-2] = '*'
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   261
        elif key[-1] == 'object' and key[0] != '*':
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   262
            if isinstance(key, tuple):
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   263
                key = list(key)
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   264
            key[0] = '*'
fcd4e6beec09 [rtags] fix NoTargetRelationTagsDict to ensure relation are tagged using '*' during initialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6899
diff changeset
   265
        super(NoTargetRelationTagsDict, self).tag_relation(key, tag)
8666
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
   266
1dd655788ece make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents: 7083
diff changeset
   267
1740
2292ae32c98f warn and drop rtags not in schema, this may be intentional; drop possibility to not specify value for bool rtags
sylvain.thenault@logilab.fr
parents: 1739
diff changeset
   268
set_log_methods(RelationTags, logging.getLogger('cubicweb.rtags'))