schema.py
branch3.5
changeset 2920 64322aa83a1d
parent 2782 998f24dabd0d
child 2931 17224e90a1c4
equal deleted inserted replaced
2919:662f35236d1c 2920:64322aa83a1d
   810     """extends default EntityType's metaclass to add workflow relations
   810     """extends default EntityType's metaclass to add workflow relations
   811     (i.e. in_state and wf_info_for).
   811     (i.e. in_state and wf_info_for).
   812     This is the default metaclass for WorkflowableEntityType
   812     This is the default metaclass for WorkflowableEntityType
   813     """
   813     """
   814     def __new__(mcs, name, bases, classdict):
   814     def __new__(mcs, name, bases, classdict):
   815         abstract = classdict.pop('abstract', False)
   815         abstract = classdict.pop('__abstract__', False)
   816         defclass = super(workflowable_definition, mcs).__new__(mcs, name, bases, classdict)
   816         cls = super(workflowable_definition, mcs).__new__(mcs, name, bases,
       
   817                                                           classdict)
   817         if not abstract:
   818         if not abstract:
   818             existing_rels = set(rdef.name for rdef in defclass.__relations__)
   819             make_workflowable(cls)
   819             if 'in_state' not in existing_rels and 'wf_info_for' not in existing_rels:
   820         return cls
   820                 in_state = ybo.SubjectRelation('State', cardinality='1*',
   821 
   821                                                # XXX automatize this
   822 def make_workflowable(cls):
   822                                                constraints=[RQLConstraint('S is ET, O state_of ET')],
   823     existing_rels = set(rdef.name for rdef in cls.__relations__)
   823                                                description=_('account state'))
   824     # let relation types defined in cw.schemas.workflow carrying
   824                 yams_add_relation(defclass.__relations__, in_state, 'in_state')
   825     # cardinality, constraints and other relation definition properties
   825                 wf_info_for = ybo.ObjectRelation('TrInfo', cardinality='1*', composite='object')
   826     if 'custom_workflow' not in existing_rels:
   826                 yams_add_relation(defclass.__relations__, wf_info_for, 'wf_info_for')
   827         rdef = ybo.SubjectRelation('Workflow')
   827         return defclass
   828         yams_add_relation(cls.__relations__, rdef, 'custom_workflow')
       
   829     if 'in_state' not in existing_rels:
       
   830         rdef = ybo.SubjectRelation('State')
       
   831         yams_add_relation(cls.__relations__, rdef, 'in_state')
       
   832     if 'wf_info_for' not in existing_rels:
       
   833         rdef = ybo.ObjectRelation('TrInfo')
       
   834         yams_add_relation(cls.__relations__, rdef, 'wf_info_for')
   828 
   835 
   829 class WorkflowableEntityType(ybo.EntityType):
   836 class WorkflowableEntityType(ybo.EntityType):
   830     __metaclass__ = workflowable_definition
   837     __metaclass__ = workflowable_definition
   831     abstract = True
   838     __abstract__ = True
   832 
   839 
   833 PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType
   840 PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType
   834 
   841 
   835 # schema loading ##############################################################
   842 # schema loading ##############################################################
   836 
   843