如何在Django-Vieflow中为用户分配任务

时间:2018-08-07 03:21:22

标签: django django-viewflow

class HelloWorldFlow(Flow):
    process_class = HelloWorldProcess
    ######### Here I start the process where i enter some text

    start = (
        flow.Start(CreateProcessView, fields=["text"])
        .Permission(auto_create=True)
        .Next(this.approve)
    )

    ######### Here i update the process view with the user name which i obtained from "asignedto"- which consist of all the user in a drop down

    approve = (
        flow.View(UpdateProcessView, fields=["asignedto"])
        .Assign(lambda act: act.process.created_by)
        .Permission(auto_create=True)
        .Next(this.task_assign)
    )
    ######### Below is the code where i am facing difficulty i am not able to know how to pass the user name in the .Assign()
    ######### This one works .Assign(username="Debasish"), however i want to assign the user based on previous workflow which is approve, where i selected from the drop down
    ######### This one do not work .Assign(username=this.approve.owner)

    task_assign = (
        flow.View(AssignTaskView)
        .Assign(this.approve.owner)
        .Next(this.check_approve)
    )
    ######### Below this its working

    check_approve = (
        flow.If(lambda activation: activation.process.approved)
        .Then(this.send)
        .Else(this.end)
    )

    send = flow.Handler(this.send_hello_world_request).Next(this.end)

    end = flow.End()

    def send_hello_world_request(self, activation):
        print(activation.process.text)

1 个答案:

答案 0 :(得分:0)

BPMN的优点之一是过程可追溯性。您无法实施不会持久化流程决策的流程。这对于过程性能分析非常方便。

BPMN中的每个任务彼此独立,并且只能对过程数据执行决策。这给流程图带来了灵活性,并允许重新排列流节点,因为它们之间仅存在数据存储依赖性。


简短的答案-将用户存储在Process模型中并使用.Assign(lambda act: act.process.granted_user_for_a_task)