Skip to content

Instantly share code, notes, and snippets.

@kracekumar kracekumar/state.py

Last active Jul 17, 2016
Embed
What would you like to do?
state machine
class Order:
pass
states = ['placed', 'dispatched', 'delivered', 'canceled', 'returned']
transitions = [
# placed
['dispatch', 'placed', 'dispatched'],
['cancel', 'placed', 'canceled'],
# dispatched
['deliver', 'dispatched', 'delivered'],
['cancel', 'dispatched', 'canceled'],
# Returned
['return', 'delivered', 'returned']
]
from transitions import Machine
machine = Machine(model=Order(), states=states, transitions=transitions, initial='placed', ignore_invalid_triggers=True)
print(machine.model.state)
#'placed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.