schema.py
changeset 5379 c082dea0731b
parent 5378 0f54a0e128ac
child 5423 e15abfdcce38
equal deleted inserted replaced
5378:0f54a0e128ac 5379:c082dea0731b
   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 class WorkflowableEntityType(ybo.EntityType):
       
   986     """Use this base class instead of :class:`EntityType` to have workflow
       
   987     relations (i.e. `in_state`, `wf_info_for` and `custom_workflow`) on your
       
   988     entity type.
       
   989     """
       
   990     __metaclass__ = workflowable_definition
       
   991     __abstract__ = True
       
   992 
       
   993 
   985 def make_workflowable(cls, in_state_descr=None):
   994 def make_workflowable(cls, in_state_descr=None):
   986     """Adds workflow relations as :class:`WorkflowableEntityType`, but usable on
   995     """Adds workflow relations as :class:`WorkflowableEntityType`, but usable on
   987     existing classes which are not using that base class.
   996     existing classes which are not using that base class.
   988     """
   997     """
   989     existing_rels = set(rdef.name for rdef in cls.__relations__)
   998     existing_rels = set(rdef.name for rdef in cls.__relations__)
   990     # let relation types defined in cw.schemas.workflow carrying
   999     # let relation types defined in cw.schemas.workflow carrying
   991     # cardinality, constraints and other relation definition properties
  1000     # cardinality, constraints and other relation definition properties
       
  1001     etype = getattr(cls, 'name', cls.__name__)
   992     if 'custom_workflow' not in existing_rels:
  1002     if 'custom_workflow' not in existing_rels:
   993         rdef = ybo.SubjectRelation('Workflow')
  1003         rdef = ybo.RelationDefinition(etype, 'custom_workflow', 'Workflow')
   994         yams_add_relation(cls.__relations__, rdef, 'custom_workflow')
  1004         yams_add_relation(cls.__relations__, rdef)
   995     if 'in_state' not in existing_rels:
  1005     if 'in_state' not in existing_rels:
   996         rdef = ybo.SubjectRelation('State', description=in_state_descr)
  1006         rdef = ybo.RelationDefinition(etype, 'in_state', 'State',
   997         yams_add_relation(cls.__relations__, rdef, 'in_state')
  1007                                       description=in_state_descr)
       
  1008         yams_add_relation(cls.__relations__, rdef)
   998     if 'wf_info_for' not in existing_rels:
  1009     if 'wf_info_for' not in existing_rels:
   999         rdef = ybo.ObjectRelation('TrInfo')
  1010         rdef = ybo.RelationDefinition('TrInfo', 'wf_info_for', etype)
  1000         yams_add_relation(cls.__relations__, rdef, 'wf_info_for')
  1011         yams_add_relation(cls.__relations__, rdef)
  1001 
       
  1002 class WorkflowableEntityType(ybo.EntityType):
       
  1003     __metaclass__ = workflowable_definition
       
  1004     __abstract__ = True
       
  1005 
  1012 
  1006 
  1013 
  1007 # schema loading ##############################################################
  1014 # schema loading ##############################################################
  1008 
  1015 
  1009 CONSTRAINTS['RQLConstraint'] = RQLConstraint
  1016 CONSTRAINTS['RQLConstraint'] = RQLConstraint