135 'WHERE S eid %(s)s, T eid %(t)s', |
135 'WHERE S eid %(s)s, T eid %(t)s', |
136 {'t': tr.eid, 's': tostate}, ('s', 't')) |
136 {'t': tr.eid, 's': tostate}, ('s', 't')) |
137 return tr |
137 return tr |
138 |
138 |
139 def add_wftransition(self, name, subworkflow, fromstates, exitpoints, |
139 def add_wftransition(self, name, subworkflow, fromstates, exitpoints, |
140 requiredgroups=(), conditions=(), **kwargs): |
140 requiredgroups=(), conditions=(), **kwargs): |
141 """add a workflow transition to this workflow""" |
141 """add a workflow transition to this workflow""" |
142 tr = self._add_transition('WorkflowTransition', name, fromstates, |
142 tr = self._add_transition('WorkflowTransition', name, fromstates, |
143 requiredgroups, conditions, **kwargs) |
143 requiredgroups, conditions, **kwargs) |
144 if hasattr(subworkflow, 'eid'): |
144 if hasattr(subworkflow, 'eid'): |
145 subworkflow = subworkflow.eid |
145 subworkflow = subworkflow.eid |
220 {'x': self.eid, 'gn': gname}, 'x') |
220 {'x': self.eid, 'gn': gname}, 'x') |
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, basestring): |
226 kwargs = {'expr': unicode(expr)} |
226 kwargs = {'expr': unicode(expr)} |
227 elif isinstance(expr, dict): |
227 else: |
|
228 assert isinstance(expr, dict) |
228 kwargs = expr |
229 kwargs = expr |
229 kwargs['x'] = self.eid |
230 kwargs['x'] = self.eid |
230 kwargs.setdefault('mainvars', u'X') |
231 kwargs.setdefault('mainvars', u'X') |
231 self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
232 self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
232 'X expression %(expr)s, T condition X ' |
233 'X expression %(expr)s, T condition X ' |
423 """generates transition that MAY be fired for the given entity, |
424 """generates transition that MAY be fired for the given entity, |
424 expected to be in this state |
425 expected to be in this state |
425 """ |
426 """ |
426 if self.current_state is None or self.current_workflow is None: |
427 if self.current_state is None or self.current_workflow is None: |
427 return |
428 return |
428 <<<<<<< /home/syt/src/fcubicweb/cubicweb/entities/wfobjs.py |
|
429 rset = self._cw.execute( |
429 rset = self._cw.execute( |
430 'Any T,N WHERE S allowed_transition T, S eid %(x)s, ' |
|
431 'T name N, T transition_of WF, WF eid %(wfeid)s', |
|
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, ' |
430 'Any T,TT, TN WHERE S allowed_transition T, S eid %(x)s, ' |
436 'T type TT, T type %(type)s, ' |
431 'T type TT, T type %(type)s, ' |
437 'T name TN, T transition_of WF, WF eid %(wfeid)s', |
432 'T name TN, T transition_of WF, WF eid %(wfeid)s', |
438 {'x': self.current_state.eid, 'type': type, |
433 {'x': self.current_state.eid, 'type': type, |
439 >>>>>>> /tmp/wfobjs.py~other.TyHPqT |
|
440 'wfeid': self.current_workflow.eid}, 'x') |
434 'wfeid': self.current_workflow.eid}, 'x') |
441 for tr in rset.entities(): |
435 for tr in rset.entities(): |
442 if tr.may_be_fired(self.eid): |
436 if tr.may_be_fired(self.eid): |
443 yield tr |
437 yield tr |
444 |
438 |
461 def fire_transition(self, tr, comment=None, commentformat=None): |
455 def fire_transition(self, tr, comment=None, commentformat=None): |
462 """change the entity's state by firing transition of the given name in |
456 """change the entity's state by firing transition of the given name in |
463 entity's workflow |
457 entity's workflow |
464 """ |
458 """ |
465 assert self.current_workflow |
459 assert self.current_workflow |
466 <<<<<<< /home/syt/src/fcubicweb/cubicweb/entities/wfobjs.py |
460 if isinstance(tr, basestring): |
|
461 tr = self.current_workflow.transition_by_name(tr) |
467 tr = self.current_workflow.transition_by_name(trname) |
462 tr = self.current_workflow.transition_by_name(trname) |
468 if tr is None: |
463 if tr is None: |
469 raise WorkflowException('not a %s transition: %s' % (self.__regid__, |
464 raise WorkflowException('not a %s transition: %s' % (self.__regid__, |
470 trname)) |
465 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 |
|
476 return self._add_trinfo(comment, commentformat, tr.eid) |
466 return self._add_trinfo(comment, commentformat, tr.eid) |
477 |
467 |
478 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
468 def change_state(self, statename, comment=None, commentformat=None, tr=None): |
479 """change the entity's state to the given state (name or entity) in |
469 """change the entity's state to the given state (name or entity) in |
480 entity's workflow. This method should only by used by manager to fix an |
470 entity's workflow. This method should only by used by manager to fix an |