Skip to content

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.

  • 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
  1. 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 BaseState
    from ..Task import Task
    from perseus.datamanager import Project
    class MyState(BaseState):
    @classmethod
    def initialize(cls):
    ...
    @classmethod
    def get_task_ids(cls) -> list[str]:
    ...
    @classmethod
    def get_tasks(
    cls, include_form: bool = True, project_id: str | None = None, **kwargs
    ) -> list[Task]:
    ...
    @classmethod
    def handle_action(cls, project: Project, task_id: str, content: dict):
    ...
  2. Register custom state

    To allow PERSEUS to use the state you will have to import it to the __init__.py file in the custom state directory. To do this, add the following line to that file:

    custom/__init__.py
    from .MyState import MyState

The class method initialize() will be executed when PERSEUS is starting up.

  1. 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 BaseState
    from perseus.security import CoreRoleName
    class MyState(BaseState):
    @classmethod
    def initialize(cls):
    MyState.add_permission(CoreRoleName.OWNER)
    MyState.add_permission(CoreRoleName.SUPPORT_L1)
  2. 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 BaseState
    from perseus.security import CoreRoleName
    class MyState(BaseState):
    @classmethod
    def 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.