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._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
231 self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
228 'X expression %(expr)s, T condition X ' |
232 'X expression %(expr)s, T condition X ' |
229 'WHERE T eid %(x)s', |
233 'WHERE T eid %(x)s', |
230 {'x': self.eid, 'expr': expr}, 'x') |
234 'T condition X WHERE T eid %(x)s', kwargs, 'x') |
231 # XXX clear caches? |
235 # XXX clear caches? |
232 |
236 |
233 |
237 |
234 class Transition(BaseTransition): |
238 class Transition(BaseTransition): |
235 """customized class for Transition entities""" |
239 """customized class for Transition entities""" |
413 self.warning("can't find default workflow for %s", self.__regid__) |
417 self.warning("can't find default workflow for %s", self.__regid__) |
414 else: |
418 else: |
415 self.warning("can't find any workflow for %s", self.__regid__) |
419 self.warning("can't find any workflow for %s", self.__regid__) |
416 return None |
420 return None |
417 |
421 |
418 def possible_transitions(self): |
422 def possible_transitions(self, type='normal'): |
419 """generates transition that MAY be fired for the given entity, |
423 """generates transition that MAY be fired for the given entity, |
420 expected to be in this state |
424 expected to be in this state |
421 """ |
425 """ |
422 if self.current_state is None or self.current_workflow is None: |
426 if self.current_state is None or self.current_workflow is None: |
423 return |
427 return |
|
428 <<<<<<< /home/syt/src/fcubicweb/cubicweb/entities/wfobjs.py |
424 rset = self._cw.execute( |
429 rset = self._cw.execute( |
425 'Any T,N WHERE S allowed_transition T, S eid %(x)s, ' |
430 'Any T,N WHERE S allowed_transition T, S eid %(x)s, ' |
426 'T name N, T transition_of WF, WF eid %(wfeid)s', |
431 'T name N, T transition_of WF, WF eid %(wfeid)s', |
427 {'x': self.current_state.eid, |
432 {'x': self.current_state.eid, |
|
433 ======= |
|
434 rset = self.req.execute( |
|
435 'Any T,TT, TN WHERE S allowed_transition T, S eid %(x)s, ' |
|
436 'T type TT, T type %(type)s, ' |
|
437 'T name TN, T transition_of WF, WF eid %(wfeid)s', |
|
438 {'x': self.current_state.eid, 'type': type, |
|
439 >>>>>>> /tmp/wfobjs.py~other.TyHPqT |
428 'wfeid': self.current_workflow.eid}, 'x') |
440 'wfeid': self.current_workflow.eid}, 'x') |
429 for tr in rset.entities(): |
441 for tr in rset.entities(): |
430 if tr.may_be_fired(self.eid): |
442 if tr.may_be_fired(self.eid): |
431 yield tr |
443 yield tr |
432 |
444 |
444 if tseid is not None: |
456 if tseid is not None: |
445 args.append( ('to_state', 'S') ) |
457 args.append( ('to_state', 'S') ) |
446 kwargs['S'] = tseid |
458 kwargs['S'] = tseid |
447 return self._cw.create_entity('TrInfo', *args, **kwargs) |
459 return self._cw.create_entity('TrInfo', *args, **kwargs) |
448 |
460 |
449 def fire_transition(self, trname, comment=None, commentformat=None): |
461 def fire_transition(self, tr, comment=None, commentformat=None): |
450 """change the entity's state by firing transition of the given name in |
462 """change the entity's state by firing transition of the given name in |
451 entity's workflow |
463 entity's workflow |
452 """ |
464 """ |
453 assert self.current_workflow |
465 assert self.current_workflow |
|
466 <<<<<<< /home/syt/src/fcubicweb/cubicweb/entities/wfobjs.py |
454 tr = self.current_workflow.transition_by_name(trname) |
467 tr = self.current_workflow.transition_by_name(trname) |
455 if tr is None: |
468 if tr is None: |
456 raise WorkflowException('not a %s transition: %s' % (self.__regid__, |
469 raise WorkflowException('not a %s transition: %s' % (self.__regid__, |
457 trname)) |
470 trname)) |
|
471 ======= |
|
472 if isinstance(tr, basestring): |
|
473 tr = self.current_workflow.transition_by_name(tr) |
|
474 assert tr is not None, 'not a %s transition: %s' % (self.id, tr) |
|
475 >>>>>>> /tmp/wfobjs.py~other.TyHPqT |
458 return self._add_trinfo(comment, commentformat, tr.eid) |
476 return self._add_trinfo(comment, commentformat, tr.eid) |
459 |
477 |
460 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
478 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
461 """change the entity's state to the given state (name or entity) in |
479 """change the entity's state to the given state (name or entity) in |
462 entity's workflow. This method should only by used by manager to fix an |
480 entity's workflow. This method should only by used by manager to fix an |