django - 通过代码运行流程 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")
解决方案
通常,“完全按代码”运行是反模式,应该避免。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
推荐阅读
- javascript - 如何使用 wp-blocks api 将原始 html 转换/解析为 wp gutenberg 块?
- node.js - AWS 使用无服务器 lambda 将用户登录到 cognito
- javascript - 当有问题的代码(似乎)不存在时,如何修复“参数列表后丢失”错误?
- kubernetes - k8s - 如何将服务帐户令牌投影到 pod
- angular - 可以将字符串转换为有效条件以在 *ngIf 中使用以过滤数据吗?
- elasticsearch - 将 ReactiveSearch 与电子商务子类别一起使用的示例
- html - 列表中的每个孩子都应该有一个唯一的“关键”道具
- excel - 我将范围设置为最后一行,我想复制它
- php - Eloquent 获取价值 多对多关系
- activemq - activemq amqp 消息订单保存