entities/wfobjs.py
branchtls-sprint
changeset 1572 469787f6ea2b
parent 1154 9b23a6836c32
child 1977 606923dff11b
equal deleted inserted replaced
1571:e9ad2724659d 1572:469787f6ea2b
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from cubicweb.entities import AnyEntity, fetch_config
     9 from cubicweb.entities import AnyEntity, fetch_config
    10 
    10 
    11  
    11 
    12 class Transition(AnyEntity):
    12 class Transition(AnyEntity):
    13     """customized class for Transition entities
    13     """customized class for Transition entities
    14 
    14 
    15     provides a specific may_be_passed method to check if the relation may be
    15     provides a specific may_be_passed method to check if the relation may be
    16     passed by the logged user
    16     passed by the logged user
    17     """
    17     """
    18     id = 'Transition'
    18     id = 'Transition'
    19     fetch_attrs, fetch_order = fetch_config(['name'])
    19     fetch_attrs, fetch_order = fetch_config(['name'])
    20                  
    20 
    21     def may_be_passed(self, eid, stateeid):
    21     def may_be_passed(self, eid, stateeid):
    22         """return true if the logged user may pass this transition
    22         """return true if the logged user may pass this transition
    23 
    23 
    24         `eid` is the eid of the object on which we may pass the transition
    24         `eid` is the eid of the object on which we may pass the transition
    25         `stateeid` is the eid of the current object'state XXX unused
    25         `stateeid` is the eid of the current object'state XXX unused
    42             return False
    42             return False
    43         return True
    43         return True
    44 
    44 
    45     def destination(self):
    45     def destination(self):
    46         return self.destination_state[0]
    46         return self.destination_state[0]
    47     
    47 
    48     def after_deletion_path(self):
    48     def after_deletion_path(self):
    49         """return (path, parameters) which should be used as redirect
    49         """return (path, parameters) which should be used as redirect
    50         information when this entity is being deleted
    50         information when this entity is being deleted
    51         """
    51         """
    52         if self.transition_of:
    52         if self.transition_of:
    53             return self.transition_of[0].rest_path(), {'vid': 'workflow'}
    53             return self.transition_of[0].rest_path(), {'vid': 'workflow'}
    54         return super(Transition, self).after_deletion_path()
    54         return super(Transition, self).after_deletion_path()
    55 
    55 
    56     
    56 
    57 class State(AnyEntity):
    57 class State(AnyEntity):
    58     """customized class for State entities
    58     """customized class for State entities
    59 
    59 
    60     provides a specific transitions method returning transitions that may be
    60     provides a specific transitions method returning transitions that may be
    61     passed by the current user for the given entity
    61     passed by the current user for the given entity
    62     """
    62     """
    63     id = 'State'
    63     id = 'State'
    64     fetch_attrs, fetch_order = fetch_config(['name'])
    64     fetch_attrs, fetch_order = fetch_config(['name'])
    65     rest_attr = 'eid'
    65     rest_attr = 'eid'
    66         
    66 
    67     def transitions(self, entity, desteid=None):
    67     def transitions(self, entity, desteid=None):
    68         rql = ('Any T,N,DS where S allowed_transition T, S eid %(x)s, '
    68         rql = ('Any T,N,DS where S allowed_transition T, S eid %(x)s, '
    69                'T name N, T destination_state DS, '
    69                'T name N, T destination_state DS, '
    70                'T transition_of ET, ET name %(et)s')
    70                'T transition_of ET, ET name %(et)s')
    71         if desteid is not None:
    71         if desteid is not None:
    73         rset = self.req.execute(rql, {'x': self.eid, 'et': str(entity.e_schema),
    73         rset = self.req.execute(rql, {'x': self.eid, 'et': str(entity.e_schema),
    74                                          'ds': desteid}, 'x')
    74                                          'ds': desteid}, 'x')
    75         for tr in rset.entities():
    75         for tr in rset.entities():
    76             if tr.may_be_passed(entity.eid, self.eid):
    76             if tr.may_be_passed(entity.eid, self.eid):
    77                 yield tr
    77                 yield tr
    78                 
    78 
    79     def after_deletion_path(self):
    79     def after_deletion_path(self):
    80         """return (path, parameters) which should be used as redirect
    80         """return (path, parameters) which should be used as redirect
    81         information when this entity is being deleted
    81         information when this entity is being deleted
    82         """
    82         """
    83         if self.state_of:
    83         if self.state_of:
    84             return self.state_of[0].rest_path(), {'vid': 'workflow'}
    84             return self.state_of[0].rest_path(), {'vid': 'workflow'}
    85         return super(State, self).after_deletion_path()
    85         return super(State, self).after_deletion_path()
    86 
    86 
    87     
    87 
    88 class TrInfo(AnyEntity):
    88 class TrInfo(AnyEntity):
    89     """customized class for Transition information entities
    89     """customized class for Transition information entities
    90     """
    90     """
    91     id = 'TrInfo'
    91     id = 'TrInfo'
    92     fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'],
    92     fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'],
    95     def for_entity(self):
    95     def for_entity(self):
    96         return self.wf_info_for and self.wf_info_for[0]
    96         return self.wf_info_for and self.wf_info_for[0]
    97     @property
    97     @property
    98     def previous_state(self):
    98     def previous_state(self):
    99         return self.from_state and self.from_state[0]
    99         return self.from_state and self.from_state[0]
   100     
   100 
   101     @property
   101     @property
   102     def new_state(self):
   102     def new_state(self):
   103         return self.to_state[0]
   103         return self.to_state[0]
   104 
   104 
   105     def after_deletion_path(self):
   105     def after_deletion_path(self):