3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
|
8 |
|
9 import logging |
|
10 |
|
11 from logilab.common.logging_ext import set_log_methods |
8 |
12 |
9 |
13 |
10 class RelationTags(object): |
14 class RelationTags(object): |
11 """a tag store for full relation definitions : |
15 """a tag store for full relation definitions : |
12 |
16 |
44 keys.remove((rtype, tagged, stype, '*')) |
48 keys.remove((rtype, tagged, stype, '*')) |
45 return keys |
49 return keys |
46 |
50 |
47 def init(self, schema): |
51 def init(self, schema): |
48 # XXX check existing keys against schema |
52 # XXX check existing keys against schema |
49 for rtype, tagged, stype, otype in self._tagdefs: |
53 for rtype, tagged, stype, otype in self._tagdefs.keys(): |
50 assert rtype in schema |
54 for ertype in (stype, rtype, otype): |
51 if stype != '*': |
55 if ertype != '*' and not ertype in schema: |
52 assert stype in schema |
56 self.warning('removing rtag for %s, undefined in schema', |
53 if otype != '*': |
57 ertype) |
54 assert otype in schema |
58 self.del_rtag(stype, rtype, otype, tagged) |
55 if self._initfunc is not None: |
59 if self._initfunc is not None: |
56 for eschema in schema.entities(): |
60 for eschema in schema.entities(): |
57 for rschema, tschemas, role in eschema.relation_definitions(True): |
61 for rschema, tschemas, role in eschema.relation_definitions(True): |
58 for tschema in tschemas: |
62 for tschema in tschemas: |
59 if role == 'subject': |
63 if role == 'subject': |
127 |
131 |
128 |
132 |
129 class RelationTagsBool(RelationTags): |
133 class RelationTagsBool(RelationTags): |
130 _allowed_values = frozenset((True, False)) |
134 _allowed_values = frozenset((True, False)) |
131 |
135 |
132 def tag_subject_of(self, key, tag=True): |
|
133 super(RelationTagsBool, self).tag_subject_of(key, tag) |
|
134 |
136 |
135 def tag_object_of(self, key, tag=True): |
137 set_log_methods(RelationTags, logging.getLogger('cubicweb.rtags')) |
136 super(RelationTagsBool, self).tag_object_of(key, tag) |
|
137 |
|
138 def tag_attribute(self, key, tag=True): |
|
139 super(RelationTagsBool, self).tag_attribute(key, tag) |
|