首页 > 解决方案 > 通过代码运行流程 Django-Viewflow

问题描述

我想完全通过代码运行我的过程。我已经设法启动了一个进程,但是我无法运行该进程的下一部分。我尝试使用“flow.Function”并调用我想要的函数,但我没有说

'Function {} should be called with task instance', 'execute'" 

并且关于这个主题的文档不是很清楚。

流.py

@flow.flow_start_func
def create_flow(activation, campos_proceso, **kwargs):
    activation.process.asignador = campos_proceso['asignador']
    activation.process.ejecutor = campos_proceso['ejecutor']
    activation.process.tipo_de_flujo = campos_proceso['tipo_de_flujo']
    activation.process.estado_del_entregable = campos_proceso[
    'estado_del_entregable']
    activation.process.save()
    activation.prepare()
    activation.done()
    return activation

@flow.flow_func
def exec_flow(activation, process_fields, **kwargs):
    activation.process.revisor = process_fields['revisor']
    activation.process.save()
    activation.prepare()
    activation.done()
    return activation

@frontend.register
class Delivery_flow(Flow):
    process_class = DeliveryProcess
    start = flow.StartFunction(create_flow).Next(this.execute)
    execute = flow.Function(exec_flow).Next(this.end)
    end = flow.End()

视图.py

def Execute(request): #campos_ejecucion, request):
    campos_ejecucion = {
    'ejecutor':request.user,
    'revisor':request.user,
    'observaciones_ejecutor':'Este es un puente magico',
    'url_ejecucion':'https://www.youtube.com/watch?v=G-yNGb0Q91Y',
    }
    campos_proceso = {
    'revisor':campos_ejecucion['revisor']
    }

    flows.Delivery_flow.execute.run()
    Entregable.objects.crear_entregable()
    return render(request, "Flujo/landing.html")

标签: djangopython-3.xdjango-viewflow

解决方案


通常,“完全按代码”运行是反模式,应该避免。Flow 类是与 URL 绑定的一组视图,因此它就像基于类的 URL 配置一样,您不需要再添加单独的视图和 URL 条目。

对于自定义视图,您可以查看说明书示例 - https://github.com/viewflow/cookbook/blob/master/custom_views/demo/bloodtest/views.py

至于实际问题,您错过了 task_loader。功能节点应该弄清楚实际执行的是什么任务。您可以在流层(使用task_loader)上执行此操作,也可以直接获取任务模型实例并将其作为函数参数传递 - http://docs.viewflow.io/viewflow_flow_nodes.html#viewflow.flow.Function


推荐阅读