schema.py
changeset 2622 3c7edaa6c6d2
parent 2616 4501ee760eec
child 2632 920bfaff60a4
equal deleted inserted replaced
2621:1b9d08840a0e 2622:3c7edaa6c6d2
    36 
    36 
    37 PURE_VIRTUAL_RTYPES = set(('identity', 'has_text',))
    37 PURE_VIRTUAL_RTYPES = set(('identity', 'has_text',))
    38 VIRTUAL_RTYPES = set(('eid', 'identity', 'has_text',))
    38 VIRTUAL_RTYPES = set(('eid', 'identity', 'has_text',))
    39 
    39 
    40 #  set of meta-relations available for every entity types
    40 #  set of meta-relations available for every entity types
    41 META_RELATIONS_TYPES = set((
    41 META_RTYPES = set((
    42     'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
    42     'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
    43     'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri',
    43     'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri',
    44     ))
    44     ))
    45 
    45 
    46 #  set of entity and relation types used to build the schema
    46 #  set of entity and relation types used to build the schema
   243     def main_attribute(self):
   243     def main_attribute(self):
   244         """convenience method that returns the *main* (i.e. the first non meta)
   244         """convenience method that returns the *main* (i.e. the first non meta)
   245         attribute defined in the entity schema
   245         attribute defined in the entity schema
   246         """
   246         """
   247         for rschema, _ in self.attribute_definitions():
   247         for rschema, _ in self.attribute_definitions():
   248             if not (rschema in META_RELATIONS_TYPES
   248             if not (rschema in META_RTYPES
   249                     or self.is_metadata(rschema)):
   249                     or self.is_metadata(rschema)):
   250                 return rschema
   250                 return rschema
   251 
   251 
   252     def add_subject_relation(self, rschema):
   252     def add_subject_relation(self, rschema):
   253         """register the relation schema as possible subject relation"""
   253         """register the relation schema as possible subject relation"""
   326             eid = getattr(rdef, 'eid', None)
   326             eid = getattr(rdef, 'eid', None)
   327         self.eid = eid
   327         self.eid = eid
   328 
   328 
   329     @property
   329     @property
   330     def meta(self):
   330     def meta(self):
   331         return self.type in META_RELATIONS_TYPES
   331         return self.type in META_RTYPES
   332 
   332 
   333     def update(self, subjschema, objschema, rdef):
   333     def update(self, subjschema, objschema, rdef):
   334         super(CubicWebRelationSchema, self).update(subjschema, objschema, rdef)
   334         super(CubicWebRelationSchema, self).update(subjschema, objschema, rdef)
   335         if not self._perms_checked and self._groups:
   335         if not self._perms_checked and self._groups:
   336             for action, groups in self._groups.iteritems():
   336             for action, groups in self._groups.iteritems():