You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It allows to easilly define a workflow, attach it to a class, and use its transitions:
importxworkflowsclassMyWorkflow(xworkflows.Workflow):
# A list of state namesstates= (
('foo', "Foo"),
('bar', "Bar"),
('baz', "Baz"),
)
# A list of transition definitions; items are (name, source states, target).transitions= (
('foobar', 'foo', 'bar'),
('gobaz', ('foo', 'bar'), 'baz'),
('bazbar', 'baz', 'bar'),
)
initial_state='foo'classMyObject(xworkflows.WorkflowEnabled):
state=MyWorkflow()
@xworkflows.transition()deffoobar(self):
return42# It is possible to use another method for a given transition.@xworkflows.transition('gobaz')defblah(self):
return13
Custom functions can be hooked to transactions, in order to run before/after a transition,
when entering a state, when leaving a state, ...:
classMyObject(xworkflows.WorkflowEnabled):
state=MyWorkflow()
@xworkflows.before_transition('foobar')defmy_hook(self, *args, **kwargs):
# *args and **kwargs are those passed to MyObject.foobar(...)pass@xworkflows.on_enter_state('bar')defmy_other_hook(self, result, *args, **kwargs):
# Will be called just after any transition entering 'bar'# result is the value returned by that transition# *args, **kwargs are the arguments/keyword arguments passed to the# transition.pass