fsm package¶
Submodules¶
fsm module¶
-
class
fsm.
InvalidTransition
[source]¶ Bases:
exceptions.Exception
Moving from an state to another is not possible.
-
class
fsm.
FiniteStateMachineMixin
[source]¶ Bases:
fsm.fsm.BaseFiniteStateMachineMixin
A drop in implementation. Ready to be used.
Replace
FIELD_NAME
in order to automatically retrieve or set from a different field.In order to use with django, just add a field
state
or as defined inFIELD_NAME
and remember to usechange_state
instead of simply assigning it-
FIELD_NAME
= 'state'¶
-
-
class
fsm.
BaseFiniteStateMachineMixin
[source]¶ Base Mixin to add a state_machine behavior.
Represents the state machine for the object.
The states and transitions should be specified in the following way:
state_machine = { 'some_state': '__all__' 'another_state': ('some_state', 'one_more_state') 'one_more_state': None }
Requires the implementation of
current_state
andset_state
-
can_change
(next_state)[source]¶ Validates if the next_state can be executed or not.
It uses the state_machine attribute in the class.
-
change_state
(next_state, **kwargs)[source]¶ Performs a transition from current state to the given next state if possible.
Callbacks will be exacuted before an after changing the state. Specific state callbacks will also be called if they are implemented in the subclass.
Parameters: next_state (str or int) – where the state must go Returns: new state. Return type: str or int Raises: InvalidTransition – If transitioning is not possible
-
get_valid_transitions
()[source]¶ Return possible states to whom a product can transition.
Returns: valid transitions Return type: tuple or list
-
on_before_change_state
(previous_state, next_state, **kwargs)[source]¶ Called before a state changes.
Parameters: - previous_state (str or int) – type depends on the definition of the states.
- next_state (str or int) – type depends on the definition of the states.
-
on_change_state
(previous_state, next_state, **kwargs)[source]¶ Called after a state changes.
Parameters: - previous_state (str or int) – type depends on the definition of the states.
- next_state (str or int) – type depends on the definition of the states.
-
set_state
(state)[source]¶ Update the internal state field.
Parameters: state (str or int) – type depends on the definition of the states.
-
state_machine
= None¶
-
Module contents¶
Initializing package.