How to decide dynamic work flow for a set of model?

472 Views Asked by At

Let consider we have 3 roles, Manager, Admin, Superadmin.

Sequence of transactions should happen like t1->t2->t3->t4.

If any employee belongs to Manager role , his transaction should happen t1->t3->t2

If any employee belongs to Admin role , his transaction should happen t1->t2->t4

If any employee belongs to Supreadmin role , his transaction should happen t1->t2

In django how to define this dynamic workflow? So on request of employee this process should follow based on there Role.

Thank you in advance.

1

There are 1 best solutions below

0
On

Generally, that sample is about non-dynamic workflow. All nodes instances counts are known at the moment of workflow definitions.

If you think about the flow from the process modeling side, visual representation and explanation to a non-technical user, the flow would be modeled as following BPMN diagram that not a far away from the textual specification:

viewflow BPMN diargam

So this directly could be translated into the viewflow class definition, where django views for the same tasks could be reused over different flow nodes, ex:

class MyFlow(Flow):
    start = flow.Start(ViewT1).Next(check_role)

    check_role = (
        flow.Switch()
        .Case(this.user_t2, cond=lambda act: act.process.created_by.role=='USER')
        .Case(this.admin_t2, cond=lambda act: act.process.created_by.role=='ADMIN')
        ...
    )

    user_t2 = flow.View(ViewT2).Next(this.user_t3)

    admin_t2 = flow.View(ViewT2).Next(this.admin_t4)

    ...

Ability to have the code that looks pretty same as the textual and visual specification the main value of the viewflow library. To do that for some cases you will need to create your own flow nodes. In the viewflow samples, you can find a dynamic split node that show how to be, if the nodes instance counts are unknown at the design time.