运行 流经代码Django-Viewflow
running flow through code Django-Viewflow
我想 运行 我的过程完全通过代码。我已经设法启动了一个流程,但我无法 运行 流程的下一部分。我尝试使用 "flow.Function" 并调用我想要的函数,但我没有说
'Function {} should be called with task instance', 'execute'"
关于这个主题的文档不是很清楚。
flows.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()
views.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")
通常,运行 "entirely by code" 是反模式,应该避免。 Flow class 是与 URLs 绑定的一组视图,所以它就像基于 class 的 URL 配置,你不需要再添加一个单独的视图和URL条目。
对于自定义视图,您可以查看说明书示例 - https://github.com/viewflow/cookbook/blob/master/custom_views/demo/bloodtest/views.py
至于真题,你漏了task_loader。功能节点应该弄清楚实际执行的是什么任务。您可以在流层上执行(使用 task_loader)或直接获取 Task 模型实例并将其作为函数参数传递 - http://docs.viewflow.io/viewflow_flow_nodes.html#viewflow.flow.Function
我想 运行 我的过程完全通过代码。我已经设法启动了一个流程,但我无法 运行 流程的下一部分。我尝试使用 "flow.Function" 并调用我想要的函数,但我没有说
'Function {} should be called with task instance', 'execute'"
关于这个主题的文档不是很清楚。
flows.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()
views.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")
通常,运行 "entirely by code" 是反模式,应该避免。 Flow class 是与 URLs 绑定的一组视图,所以它就像基于 class 的 URL 配置,你不需要再添加一个单独的视图和URL条目。
对于自定义视图,您可以查看说明书示例 - https://github.com/viewflow/cookbook/blob/master/custom_views/demo/bloodtest/views.py
至于真题,你漏了task_loader。功能节点应该弄清楚实际执行的是什么任务。您可以在流层上执行(使用 task_loader)或直接获取 Task 模型实例并将其作为函数参数传递 - http://docs.viewflow.io/viewflow_flow_nodes.html#viewflow.flow.Function