schemas/workflow.py
changeset 10092 f0363da0b5a0
parent 9242 564bdd4dbf8f
child 10666 7f6b5f023884
equal deleted inserted replaced
10091:09878c2f8621 10092:f0363da0b5a0
    22 _ = unicode
    22 _ = unicode
    23 
    23 
    24 from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
    24 from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
    25                             SubjectRelation,
    25                             SubjectRelation,
    26                             RichString, String, Int)
    26                             RichString, String, Int)
    27 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    27 from cubicweb.schema import RQLConstraint
    28 from cubicweb.schemas import (PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS,
    28 from cubicweb.schemas import (PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS,
    29                               RO_REL_PERMS)
    29                               RO_REL_PERMS)
    30 
    30 
    31 class Workflow(EntityType):
    31 class Workflow(EntityType):
    32     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    32     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    60 class State(EntityType):
    60 class State(EntityType):
    61     """used to associate simple states to an entity type and/or to define
    61     """used to associate simple states to an entity type and/or to define
    62     workflows
    62     workflows
    63     """
    63     """
    64     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    64     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    65 
    65     __unique_together__ = [('name', 'state_of')]
    66     name = String(required=True, indexed=True, internationalizable=True,
    66     name = String(required=True, indexed=True, internationalizable=True, maxsize=256)
    67                   maxsize=256,
       
    68                   constraints=[RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N', 'Y',
       
    69                                                    _('workflow already has a state of that name'))])
       
    70     description = RichString(default_format='text/rest',
    67     description = RichString(default_format='text/rest',
    71                              description=_('semantic description of this state'))
    68                              description=_('semantic description of this state'))
    72 
    69 
    73     # XXX should be on BaseTransition w/ AND/OR selectors when we will
    70     # XXX should be on BaseTransition w/ AND/OR selectors when we will
    74     # implements #345274
    71     # implements #345274
    75     allowed_transition = SubjectRelation('BaseTransition', cardinality='**',
    72     allowed_transition = SubjectRelation('BaseTransition', cardinality='**',
    76                                          constraints=[RQLConstraint('S state_of WF, O transition_of WF',
    73                                          constraints=[RQLConstraint('S state_of WF, O transition_of WF',
    77                                                                     msg=_('state and transition don\'t belong the the same workflow'))],
    74                                                                     msg=_('state and transition don\'t belong the the same workflow'))],
    78                                          description=_('allowed transitions from this state'))
    75                                          description=_('allowed transitions from this state'))
    79     state_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    76     state_of = SubjectRelation('Workflow', cardinality='1*', composite='object', inlined=True,
    80                                description=_('workflow to which this state belongs'),
    77                                description=_('workflow to which this state belongs'))
    81                                constraints=[RQLUniqueConstraint('S name N, Y state_of O, Y name N', 'Y',
       
    82                                                                 _('workflow already has a state of that name'))])
       
    83 
    78 
    84 
    79 
    85 class BaseTransition(EntityType):
    80 class BaseTransition(EntityType):
    86     """abstract base class for transitions"""
    81     """abstract base class for transitions"""
    87     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    82     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    88 
    83     __unique_together__ = [('name', 'transition_of')]
    89     name = String(required=True, indexed=True, internationalizable=True,
    84 
    90                   maxsize=256,
    85     name = String(required=True, indexed=True, internationalizable=True, maxsize=256)
    91                   constraints=[RQLUniqueConstraint('S name N, S transition_of WF, Y transition_of WF, Y name N', 'Y',
       
    92                                                    _('workflow already has a transition of that name'))])
       
    93     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    86     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    94     description = RichString(description=_('semantic description of this transition'))
    87     description = RichString(description=_('semantic description of this transition'))
    95 
    88 
    96     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    89     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object', inlined=True,
    97                                     description=_('workflow to which this transition belongs'),
    90                                     description=_('workflow to which this transition belongs'))
    98                                     constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N', 'Y',
       
    99                                                                      _('workflow already has a transition of that name'))])
       
   100 
    91 
   101 
    92 
   102 class require_group(RelationDefinition):
    93 class require_group(RelationDefinition):
   103     """group in which a user should be to be allowed to pass this transition"""
    94     """group in which a user should be to be allowed to pass this transition"""
   104     __permissions__ = PUB_SYSTEM_REL_PERMS
    95     __permissions__ = PUB_SYSTEM_REL_PERMS