entity.py
changeset 7702 73cadb5d0097
parent 7552 82dde8276a5b
child 7794 aed065b97f12
equal deleted inserted replaced
7696:1541d9e6b242 7702:73cadb5d0097
    94     :type rest_var: str
    94     :type rest_var: str
    95     :cvar rest_var: indicates which attribute should be used to build REST urls
    95     :cvar rest_var: indicates which attribute should be used to build REST urls
    96                     If None is specified, the first non-meta attribute will
    96                     If None is specified, the first non-meta attribute will
    97                     be used
    97                     be used
    98 
    98 
    99     :type skip_copy_for: list
    99     :type cw_skip_copy_for: list
   100     :cvar skip_copy_for: a list of relations that should be skipped when copying
   100     :cvar cw_skip_copy_for: a list of couples (rtype, role) for each relation
   101                          this kind of entity. Note that some relations such
   101                             that should be skipped when copying
   102                          as composite relations or relations that have '?1' as object
   102                             this kind of entity. Note that some relations such
   103                          cardinality are always skipped.
   103                             as composite relations or relations that have '?1' as object
       
   104                             cardinality are always skipped.
   104     """
   105     """
   105     __registry__ = 'etypes'
   106     __registry__ = 'etypes'
   106     __select__ = yes()
   107     __select__ = yes()
   107 
   108 
   108     # class attributes that must be set in class definition
   109     # class attributes that must be set in class definition
   109     rest_attr = None
   110     rest_attr = None
   110     fetch_attrs = None
   111     fetch_attrs = None
   111     skip_copy_for = ('in_state',) # XXX turn into a set
   112     skip_copy_for = () # bw compat (< 3.14), use cw_skip_copy_for instead
       
   113     cw_skip_copy_for = [('in_state', 'subject')]
   112     # class attributes set automatically at registration time
   114     # class attributes set automatically at registration time
   113     e_schema = None
   115     e_schema = None
   114 
   116 
   115     @classmethod
   117     @classmethod
   116     def __initialize__(cls, schema):
   118     def __initialize__(cls, schema):
   540         By default meta and composite relations are skipped.
   542         By default meta and composite relations are skipped.
   541         Overrides this if you want another behaviour
   543         Overrides this if you want another behaviour
   542         """
   544         """
   543         assert self.has_eid()
   545         assert self.has_eid()
   544         execute = self._cw.execute
   546         execute = self._cw.execute
       
   547         skip_copy_for = {'subject': set(), 'object': set()}
       
   548         for rtype in self.skip_copy_for:
       
   549             skip_copy_for['subject'].add(rtype)
       
   550             warn('[3.14] skip_copy_for on entity classes (%s) is deprecated, '
       
   551                  'use cw_skip_for instead with list of couples (rtype, role)' % self.__regid__,
       
   552                  DeprecationWarning)
       
   553         for rtype, role in self.cw_skip_copy_for:
       
   554             assert role in ('subject', 'object'), role
       
   555             skip_copy_for[role].add(rtype)
   545         for rschema in self.e_schema.subject_relations():
   556         for rschema in self.e_schema.subject_relations():
   546             if rschema.final or rschema.meta:
   557             if rschema.final or rschema.meta:
   547                 continue
   558                 continue
   548             # skip already defined relations
   559             # skip already defined relations
   549             if getattr(self, rschema.type):
   560             if getattr(self, rschema.type):
   550                 continue
   561                 continue
   551             if rschema.type in self.skip_copy_for:
   562             if rschema.type in skip_copy_for['subject']:
   552                 continue
   563                 continue
   553             # skip composite relation
   564             # skip composite relation
   554             rdef = self.e_schema.rdef(rschema)
   565             rdef = self.e_schema.rdef(rschema)
   555             if rdef.composite:
   566             if rdef.composite:
   556                 continue
   567                 continue
   565         for rschema in self.e_schema.object_relations():
   576         for rschema in self.e_schema.object_relations():
   566             if rschema.meta:
   577             if rschema.meta:
   567                 continue
   578                 continue
   568             # skip already defined relations
   579             # skip already defined relations
   569             if self.related(rschema.type, 'object'):
   580             if self.related(rschema.type, 'object'):
       
   581                 continue
       
   582             if rschema.type in skip_copy_for['object']:
   570                 continue
   583                 continue
   571             rdef = self.e_schema.rdef(rschema, 'object')
   584             rdef = self.e_schema.rdef(rschema, 'object')
   572             # skip composite relation
   585             # skip composite relation
   573             if rdef.composite:
   586             if rdef.composite:
   574                 continue
   587                 continue