Skip to content

Instantly share code, notes, and snippets.

@kracekumar
Last active July 17, 2016 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kracekumar/dc5628713340acbda373c6f6f54e72bb to your computer and use it in GitHub Desktop.
Save kracekumar/dc5628713340acbda373c6f6f54e72bb to your computer and use it in GitHub Desktop.
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