State Machine¶
Resources can be registered with a state machine to manage its states. MorpFW uses PyTransitions as its default state machine engine and provides the REST API to transition the states of resources.
- class morpfw.interfaces.IStateMachine¶
- abstract get_triggers() List ¶
Returns list of available triggers
- abstract property readonly_states: List¶
List of readonly states
- abstract property state: Optional[str]¶
Current resource state
- abstract property states: List¶
List of
pytransitions
states
- abstract property transitions: List¶
List of
pytransitions
transitions
Registering State Machine Provider¶
To register a state machine provider for your resource model, simply register based on following example:
import typing
from dataclasses import dataclass
import morpfw
from .app import App
from .model import PageModel
class PageStateMachine(morpfw.StateMachine):
states = ['new', 'pending', 'approved']
transitions = [
{'trigger': 'approve', 'source': [
'new', 'pending'], 'dest': 'approved'},
{'trigger': 'submit', 'source': 'new', 'dest': 'pending'}
]
@App.statemachine(model=PageModel)
def get_pagemodel_statemachine(context):
return PageStateMachine(context)