221 assert rset, '%s is not a known group' % gname |
221 assert rset, '%s is not a known group' % gname |
222 if isinstance(conditions, basestring): |
222 if isinstance(conditions, basestring): |
223 conditions = (conditions,) |
223 conditions = (conditions,) |
224 for expr in conditions: |
224 for expr in conditions: |
225 if isinstance(expr, str): |
225 if isinstance(expr, str): |
226 expr = unicode(expr) |
226 kwargs = {'expr': unicode(expr)} |
|
227 elif isinstance(expr, dict): |
|
228 kwargs = expr |
|
229 kwargs['x'] = self.eid |
|
230 kwargs.setdefault('mainvars', u'X') |
227 self.req.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
231 self.req.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
228 'X expression %(expr)s, T condition X ' |
232 'X expression %(expr)s, X mainvars %(mainvars)s, ' |
229 'WHERE T eid %(x)s', |
233 'T condition X WHERE T eid %(x)s', kwargs, 'x') |
230 {'x': self.eid, 'expr': expr}, 'x') |
|
231 # XXX clear caches? |
234 # XXX clear caches? |
232 |
235 |
233 |
236 |
234 class Transition(BaseTransition): |
237 class Transition(BaseTransition): |
235 """customized class for Transition entities""" |
238 """customized class for Transition entities""" |
413 self.warning("can't find default workflow for %s", self.id) |
416 self.warning("can't find default workflow for %s", self.id) |
414 else: |
417 else: |
415 self.warning("can't find any workflow for %s", self.id) |
418 self.warning("can't find any workflow for %s", self.id) |
416 return None |
419 return None |
417 |
420 |
418 def possible_transitions(self): |
421 def possible_transitions(self, type='normal'): |
419 """generates transition that MAY be fired for the given entity, |
422 """generates transition that MAY be fired for the given entity, |
420 expected to be in this state |
423 expected to be in this state |
421 """ |
424 """ |
422 if self.current_state is None or self.current_workflow is None: |
425 if self.current_state is None or self.current_workflow is None: |
423 return |
426 return |
424 rset = self.req.execute( |
427 rset = self.req.execute( |
425 'Any T,N WHERE S allowed_transition T, S eid %(x)s, ' |
428 'Any T,TT, TN WHERE S allowed_transition T, S eid %(x)s, ' |
426 'T name N, T transition_of WF, WF eid %(wfeid)s', |
429 'T type TT, T type %(type)s, ' |
427 {'x': self.current_state.eid, |
430 'T name TN, T transition_of WF, WF eid %(wfeid)s', |
|
431 {'x': self.current_state.eid, 'type': type, |
428 'wfeid': self.current_workflow.eid}, 'x') |
432 'wfeid': self.current_workflow.eid}, 'x') |
429 for tr in rset.entities(): |
433 for tr in rset.entities(): |
430 if tr.may_be_fired(self.eid): |
434 if tr.may_be_fired(self.eid): |
431 yield tr |
435 yield tr |
432 |
436 |
444 if tseid is not None: |
448 if tseid is not None: |
445 args.append( ('to_state', 'S') ) |
449 args.append( ('to_state', 'S') ) |
446 kwargs['S'] = tseid |
450 kwargs['S'] = tseid |
447 return self.req.create_entity('TrInfo', *args, **kwargs) |
451 return self.req.create_entity('TrInfo', *args, **kwargs) |
448 |
452 |
449 def fire_transition(self, trname, comment=None, commentformat=None): |
453 def fire_transition(self, tr, comment=None, commentformat=None): |
450 """change the entity's state by firing transition of the given name in |
454 """change the entity's state by firing transition of the given name in |
451 entity's workflow |
455 entity's workflow |
452 """ |
456 """ |
453 assert self.current_workflow |
457 assert self.current_workflow |
454 tr = self.current_workflow.transition_by_name(trname) |
458 if isinstance(tr, basestring): |
455 assert tr is not None, 'not a %s transition: %s' % (self.id, trname) |
459 tr = self.current_workflow.transition_by_name(tr) |
|
460 assert tr is not None, 'not a %s transition: %s' % (self.id, tr) |
456 return self._add_trinfo(comment, commentformat, tr.eid) |
461 return self._add_trinfo(comment, commentformat, tr.eid) |
457 |
462 |
458 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
463 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
459 """change the entity's state to the given state (name or entity) in |
464 """change the entity's state to the given state (name or entity) in |
460 entity's workflow. This method should only by used by manager to fix an |
465 entity's workflow. This method should only by used by manager to fix an |