Exemple :

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 "assigned"
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'
# short for ticket.state == TicketWorkflow.states.new ticket.state.is_new
class SomeObject(xworkflows.WorkflowEnabled): @transition('bar') def gobar(self, x): if x != 42: raise xworkflows.AbortTransition()
>>> ticket.state State('assigned') >>> ticket.state.transitions [Transition('reassign'), Transition('close')]
class MyModel(django_xworkflows.XWorkflowEnabled): state = MyWorkflow()
>>> MyModel().gobar(log=True, save=True) # default options >>> django_xworkflows.TransitionLog.objects.all() [<TransitionLog(obj, 'gobar')>]
| XWorkflows | 1 |
|---|---|
| Objectifs | 2 |
| Définir un workflow | 3 |
| Utiliser un workflow | 4 |
| Actions | 5 |
| Fonctions complémentaires | 6 |
| Intégration avec Django | 7 |
| 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 |