predicates.py
changeset 9344 4da3ef764395
parent 9256 697a8181ba30
child 9547 43aace16a953
child 9928 0d831b40fa48
equal deleted inserted replaced
9343:cf21813d7003 9344:4da3ef764395
  1212     def __str__(self):
  1212     def __str__(self):
  1213         return '%s(%s)' % (self.__class__.__name__,
  1213         return '%s(%s)' % (self.__class__.__name__,
  1214                            ','.join(str(s) for s in self.expected))
  1214                            ','.join(str(s) for s in self.expected))
  1215 
  1215 
  1216 
  1216 
  1217 def on_fire_transition(etype, tr_name, from_state_name=None):
  1217 def on_fire_transition(etype, tr_names, from_state_name=None):
  1218     """Return 1 when entity of the type `etype` is going through transition of
  1218     """Return 1 when entity of the type `etype` is going through transition of
  1219     the name `tr_name`.
  1219     a name included in `tr_names`.
  1220 
       
  1221     If `from_state_name` is specified, this predicate will also check the
       
  1222     incoming state.
       
  1223 
  1220 
  1224     You should use this predicate on 'after_add_entity' hook, since it's actually
  1221     You should use this predicate on 'after_add_entity' hook, since it's actually
  1225     looking for addition of `TrInfo` entities. Hence in the hook, `self.entity`
  1222     looking for addition of `TrInfo` entities. Hence in the hook, `self.entity`
  1226     will reference the matching `TrInfo` entity, allowing to get all the
  1223     will reference the matching `TrInfo` entity, allowing to get all the
  1227     transition details (including the entity to which is applied the transition
  1224     transition details (including the entity to which is applied the transition
  1228     but also its original state, transition, destination state, user...).
  1225     but also its original state, transition, destination state, user...).
  1229 
  1226 
  1230     See :class:`cubicweb.entities.wfobjs.TrInfo` for more information.
  1227     See :class:`cubicweb.entities.wfobjs.TrInfo` for more information.
  1231     """
  1228     """
       
  1229     if from_state_name is not None:
       
  1230         warn("on_fire_transition's from_state_name argument is unused", DeprecationWarning)
       
  1231     if isinstance(tr_names, basestring):
       
  1232         tr_names = set((tr_names,))
  1232     def match_etype_and_transition(trinfo):
  1233     def match_etype_and_transition(trinfo):
  1233         # take care trinfo.transition is None when calling change_state
  1234         # take care trinfo.transition is None when calling change_state
  1234         return (trinfo.transition and trinfo.transition.name == tr_name
  1235         return (trinfo.transition and trinfo.transition.name in tr_names
  1235                 # is_instance() first two arguments are 'cls' (unused, so giving
  1236                 # is_instance() first two arguments are 'cls' (unused, so giving
  1236                 # None is fine) and the request/session
  1237                 # None is fine) and the request/session
  1237                 and is_instance(etype)(None, trinfo._cw, entity=trinfo.for_entity))
  1238                 and is_instance(etype)(None, trinfo._cw, entity=trinfo.for_entity))
  1238 
  1239 
  1239     return is_instance('TrInfo') & score_entity(match_etype_and_transition)
  1240     return is_instance('TrInfo') & score_entity(match_etype_and_transition)