1. State initialization
You have two options when creating a new state: You can either add a basic state that provides tasks to the users, or you can add a push state that simply just pushes incoming projects to the next state.
This step-by-step guide is about a standard state. Learn more about the PushState here.
Directory structure
Section titled “Directory structure”Directoryperseus
Directorystates
Directorycustom/ Directory for custom states
- __init__.py
- TemplateBasic.py Tip: Use the template to speed up the process
- …
- __init__.py
- BaseState.py Base state (parent class) for a custom state
- PushState.py
- …
Initial state structure
Section titled “Initial state structure”-
Add a new file
Start by adding a new file to your custom state directory and name it like you want, for example
MyState.py.custom/MyState.py from ..BaseState import BaseStatefrom ..Task import Taskfrom perseus.datamanager import Projectclass MyState(BaseState):@classmethoddef initialize(cls):...@classmethoddef get_task_ids(cls) -> list[str]:...@classmethoddef get_tasks(cls, include_form: bool = True, project_id: str | None = None, **kwargs) -> list[Task]:...@classmethoddef handle_action(cls, project: Project, task_id: str, content: dict):... -
Register custom state
To allow PERSEUS to use the state you will have to import it to the
__init__.pyfile in the custom state directory. To do this, add the following line to that file:custom/__init__.py from .MyState import MyState
Initialize state
Section titled “Initialize state”The class method initialize() will be executed when PERSEUS is starting up.
-
Add permissions
First, you need to set the permissions for the new state by using its
add_permission()method. Add all roles that should have access to this state. You can view a list of all roles here.custom/MyState.py from ..BaseState import BaseStatefrom perseus.security import CoreRoleNameclass MyState(BaseState):@classmethoddef initialize(cls):MyState.add_permission(CoreRoleName.OWNER)MyState.add_permission(CoreRoleName.SUPPORT_L1) -
Add a frontend menu item
If this state should return tasks and therefore needs to be viewed from the frontend, add a menu item by using the state’s
add_frontend_menu_item()method. The first parameter will be used as displayed text, the second defines the icon that will be shown.custom/MyState.py from ..BaseState import BaseStatefrom perseus.security import CoreRoleNameclass MyState(BaseState):@classmethoddef initialize(cls):MyState.add_permission(CoreRoleName.OWNER)MyState.add_permission(CoreRoleName.SUPPORT_L1)MyState.add_frontend_menu_item("Menu Item Text", "Business")
Next, let’s assign user tasks to the state.