class TicketWorkflow(xworkflows.Workflow): states = [ ('new', _(u"New")), ('assigned', _(u"Assigned")), ('closed', _(u"Closed")), ] transitions = [ ('assign', ['new'], 'assigned'), ('reject', ['assigned'], 'new'), ('reassign', ['assigned'], 'assigned'), ('close', ['new', 'assigned'], 'closed'), ] initial_state = 'new'
class Ticket(xworkflows.WorkflowEnabled): state = TicketWorkflow() >>> ticket = MyTicket() >>> ticket.state State('new') >>> ticket.assign() >>> ticket.state State('assigned') >>> ticket.assign() Traceback (most recent call last): File "<stdin>", line 1, in <module> InvalidTransitionError: Transition "assign" isn't available from state "new"
class Ticket(xworkflows.WorkflowEnabled): state = TicketWorkflow() @transition() def assign(self, to): self.assignee = to >>> ticket = MyTicket() >>> ticket.state State('new') >>> ticket.assign('ponyconseil') >>> ticket.state State('assigned') >>> ticket.assignee 'ponyconseil'
if ticket.state.is_new: # short for <ticket.state == TicketWorkflow.states.new> class SomeObject(xworkflows.WorkflowEnabled): @transition('bar') def gobar(self, x): # In case 'bar' has another use (attribute, ...) if x != 42: raise xworkflows.AbortTransition() >>> ticket.state State('assigned') >>> ticket.state.transitions [Transition('reassign'), Transition('close')]
http://github.com/rbarrois/django_xworkflows/
class MyModel(django_xworkflows.XWorkflowEnabled): state = MyWorkflow() MyModel().gobar(log=True, save=True) django_xworkflows.TransitionLog.objects.all() [<TransitionLog(obj, 'gobar')>]
XWorkflows - Principes | 1 |
---|---|
Définition | 2 |
Utilisation | 3 |
Actions | 4 |
Fonctions complémentaires | 5 |
Intégration avec Django | 6 |
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |