How to create a django ViewFlow process programmatically

前端 未结 3 1505
离开以前
离开以前 2020-12-02 21:26

Synopsis

I\'m developing a web application to learn Django (python 3.4 & Django 1.6.10). The web app has complex and often updated workflows. I decided

3条回答
  •  渐次进展
    2020-12-02 22:00

    There are two additional Start build-in Tasks available for Flows

    StartFunction - starts flow when the function called somewhere:

    @flow_start_func
    def create_flow(activation, **kwargs):
        activation.prepare()
        activation.done()
        return activation
    
    class FunctionFlow(Flow):
        start = flow.StartFunction(create_flow) \
            .Next(this.end)
    
    # somewhere in the code
    FunctionFlow.start.run(**some_kwargs)
    

    StartSignal - starts flow on django signal receive:

    class SignalFlow(Flow):
        start = flow.StartSignal(some_signal, create_flow) \      
            .Next(this.end)
    

    You can check the usage for them, and rest of build-in task in this viewflow test suite.

    For manually process the task state, first you should get the task from the database, activate it, and call any activation method.

    task  = MyFlow.task_cls.objects.get(...)
    activation = task.activate()
    if  activation.undo.can_proceed():
        activation.undo()
    

    Any activation transition have .can_proceed() method, helps you to check, is the task in the state that allows the transition.

提交回复
热议问题