rtags.py
brancholdstable
changeset 7074 e4580e5f0703
parent 6900 fcd4e6beec09
child 7083 b8e35cde46e9
equal deleted inserted replaced
6749:48f468f33704 7074:e4580e5f0703
   103         if self._initfunc is not None:
   103         if self._initfunc is not None:
   104             self.apply(schema, self._initfunc)
   104             self.apply(schema, self._initfunc)
   105 
   105 
   106     def apply(self, schema, func):
   106     def apply(self, schema, func):
   107         for eschema in schema.entities():
   107         for eschema in schema.entities():
       
   108             if eschema.final:
       
   109                 continue
   108             for rschema, tschemas, role in eschema.relation_definitions(True):
   110             for rschema, tschemas, role in eschema.relation_definitions(True):
   109                 for tschema in tschemas:
   111                 for tschema in tschemas:
   110                     if role == 'subject':
   112                     if role == 'subject':
   111                         sschema, oschema = eschema, tschema
   113                         sschema, oschema = eschema, tschema
   112                     else:
   114                     else:
   214 
   216 
   215     @property
   217     @property
   216     def name(self):
   218     def name(self):
   217         return self.__class__.name
   219         return self.__class__.name
   218 
   220 
       
   221     # tag_subject_of / tag_object_of issue warning if '*' is not given as target
       
   222     # type, while tag_relation handle it silently since it may be used during
       
   223     # initialization
   219     def tag_subject_of(self, key, tag):
   224     def tag_subject_of(self, key, tag):
   220         subj, rtype, obj = key
   225         subj, rtype, obj = key
   221         if obj != '*':
   226         if obj != '*':
   222             self.warning('using explict target type in %s.tag_subject_of() '
   227             self.warning('using explict target type in %s.tag_subject_of() '
   223                          'has no effect, use (%s, %s, "*") instead of (%s, %s, %s)',
   228                          'has no effect, use (%s, %s, "*") instead of (%s, %s, %s)',
   230             self.warning('using explict subject type in %s.tag_object_of() '
   235             self.warning('using explict subject type in %s.tag_object_of() '
   231                          'has no effect, use ("*", %s, %s) instead of (%s, %s, %s)',
   236                          'has no effect, use ("*", %s, %s) instead of (%s, %s, %s)',
   232                          self.name, rtype, obj, subj, rtype, obj)
   237                          self.name, rtype, obj, subj, rtype, obj)
   233         super(NoTargetRelationTagsDict, self).tag_object_of(('*', rtype, obj), tag)
   238         super(NoTargetRelationTagsDict, self).tag_object_of(('*', rtype, obj), tag)
   234 
   239 
   235 
   240     def tag_relation(self, key, tag):
       
   241         if key[-1] == 'subject' and key[-2] != '*':
       
   242             if isinstance(key, tuple):
       
   243                 key = list(key)
       
   244             key[-2] = '*'
       
   245         elif key[-1] == 'object' and key[0] != '*':
       
   246             if isinstance(key, tuple):
       
   247                 key = list(key)
       
   248             key[0] = '*'
       
   249         super(NoTargetRelationTagsDict, self).tag_relation(key, tag)
   236 set_log_methods(RelationTags, logging.getLogger('cubicweb.rtags'))
   250 set_log_methods(RelationTags, logging.getLogger('cubicweb.rtags'))