schema.py
changeset 5378 0f54a0e128ac
parent 5372 b74eed7e8b37
child 5379 c082dea0731b
equal deleted inserted replaced
5374:9732efc9d599 5378:0f54a0e128ac
   613 
   613 
   614     def serialize(self):
   614     def serialize(self):
   615         # start with a comma for bw compat, see below
   615         # start with a comma for bw compat, see below
   616         return ';' + self.mainvars + ';' + self.restriction
   616         return ';' + self.mainvars + ';' + self.restriction
   617 
   617 
       
   618     @classmethod
   618     def deserialize(cls, value):
   619     def deserialize(cls, value):
   619         # XXX < 3.5.10 bw compat
   620         # XXX < 3.5.10 bw compat
   620         if not value.startswith(';'):
   621         if not value.startswith(';'):
   621             return cls(value)
   622             return cls(value)
   622         _, mainvars, restriction = value.split(';', 2)
   623         _, mainvars, restriction = value.split(';', 2)
   623         return cls(restriction, mainvars)
   624         return cls(restriction, mainvars)
   624     deserialize = classmethod(deserialize)
       
   625 
   625 
   626     def check(self, entity, rtype, value):
   626     def check(self, entity, rtype, value):
   627         """return true if the value satisfy the constraint, else false"""
   627         """return true if the value satisfy the constraint, else false"""
   628         # implemented as a hook in the repository
   628         # implemented as a hook in the repository
   629         return 1
   629         return 1
   969 
   969 
   970 from yams.buildobjs import _add_relation as yams_add_relation
   970 from yams.buildobjs import _add_relation as yams_add_relation
   971 
   971 
   972 class workflowable_definition(ybo.metadefinition):
   972 class workflowable_definition(ybo.metadefinition):
   973     """extends default EntityType's metaclass to add workflow relations
   973     """extends default EntityType's metaclass to add workflow relations
   974     (i.e. in_state and wf_info_for).
   974     (i.e. in_state, wf_info_for and custom_workflow). This is the default
   975     This is the default metaclass for WorkflowableEntityType
   975     metaclass for WorkflowableEntityType.
   976     """
   976     """
   977     def __new__(mcs, name, bases, classdict):
   977     def __new__(mcs, name, bases, classdict):
   978         abstract = classdict.pop('__abstract__', False)
   978         abstract = classdict.pop('__abstract__', False)
   979         cls = super(workflowable_definition, mcs).__new__(mcs, name, bases,
   979         cls = super(workflowable_definition, mcs).__new__(mcs, name, bases,
   980                                                           classdict)
   980                                                           classdict)
   981         if not abstract:
   981         if not abstract:
   982             make_workflowable(cls)
   982             make_workflowable(cls)
   983         return cls
   983         return cls
   984 
   984 
   985 def make_workflowable(cls, in_state_descr=None):
   985 def make_workflowable(cls, in_state_descr=None):
       
   986     """Adds workflow relations as :class:`WorkflowableEntityType`, but usable on
       
   987     existing classes which are not using that base class.
       
   988     """
   986     existing_rels = set(rdef.name for rdef in cls.__relations__)
   989     existing_rels = set(rdef.name for rdef in cls.__relations__)
   987     # let relation types defined in cw.schemas.workflow carrying
   990     # let relation types defined in cw.schemas.workflow carrying
   988     # cardinality, constraints and other relation definition properties
   991     # cardinality, constraints and other relation definition properties
   989     if 'custom_workflow' not in existing_rels:
   992     if 'custom_workflow' not in existing_rels:
   990         rdef = ybo.SubjectRelation('Workflow')
   993         rdef = ybo.SubjectRelation('Workflow')