3. Handle state tasks
Add a new class method to your state class called handle_action().
This method will be executed when the frontend submits a task for this state.
from perseus.datamanager import Project
class MyState(BaseState): ...
@classmethod def handle_action(cls, project: Project, task_id: str, content: dict): ...In this method, you will receive the following parameters:
project: The associated projecttask_id: The task ID of the submitted taskcontent: A dictionary containing the submitted frontend data (the IDs of the form input fields become the keys of the dictionary, learn more about forms here)
Most of the time, you probably want to check some value in the content and depending on that trigger an event on the project that will eventually move it to another state. This could look like the following:
@classmethoddef handle_action(cls, project: Project, task_id: str, content: dict): if task_id == "MY_TASK_ID" and "decision" in content: MyState.trigger_event( project=project, value=content["decision"], comment=f"This comment will be visible in the event queue - the decision was {content["decision"]}", by=MyState.task_assignee(project, task_id), )Learn more about events here.
In the last step, we will configure state pretreatments which help preparing projects for a state when entering it.