Django视图流-定义API流 [英] Django viewflows - Defining an API flow

查看:68
本文介绍了Django视图流-定义API流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个API端点,/api/create/.这会根据从客户端收到的有效负载在数据库中创建一个新条目.

I've an API endpoint, /api/create/. This creates a new entry in the DB depending upon the payload received from the client.

Payload - { 
'field1': 'value1`,
'field2': 'value2`,
'field3': 'value3`,
'field4': 'value4`,
'type': 'A'
}

现在取决于类型,我有一个特定的工作流程.例如:- Type A 在保存数据之前需要执行某些任务, Type B 具有其自己的一组操作.

Now depending on the type, I've a specific workflow. For eg:- Type A needs to perform certain tasks before saving the data, Type B has its own set of operations.

我没有任何UI,只有来自POST请求的请求.如何在这种用例中使用 django-viewflows ?

I don't have any UI, just the requests coming over the POST request. How can I use django-viewflows for such a use-case?

已更新

我能够使用 WorkFlowClass.start.run()以编程方式运行工作流.它完美地启动了工作流程.但是,不是完整的工作流程.完成工作流程的Node1(启动)后,它不会转到Node2.意思是,仅调用工作流的第一个任务,而不调用后续任务.

I was able to run the workflow programmatically using WorkFlowClass.start.run(). It starts the workflow perfectly. However, not the complete workflow. Upon completing Node1(start) of workflow, it does not goes to Node2. Meaning, only first task of the workflow is called, not the subsequent tasks.

这是我的工作流程.

class FunctionFlow1(Flow):
    start = flow.StartFunction(function1) \
        .Next(this.task2)
    task2 = flow.StartFunction(function2) \
        .Next(this.end)
    end = flow.End()

@flow_start_func
def function1(activation, **kwargs):
    print('Func1 Called.')
    activation.prepare()
    activation.done()
    return activation

@flow_start_func
def function1(activation, **kwargs):
    print('Func2 Called.')
    activation.prepare()
    activation.done()
    return activation

task2 不被调用.为什么?

推荐答案

您可以使用 viewflow.rest 包创建REST API.请查看演示项目并查看流程休息文档.

You can use viewflow.rest package to create the REST APIs. Please look at the demo project and view flow rest documentation.

请注意,此功能仅在仅PRO

https://github.com/viewflow/cookbook/tree/master/react_ui

http://docs.viewflow.io/viewflow_rest.html

viewflow.rest包提供了带有REST的流实现界面.

viewflow.rest package provides a flow implementation with the REST interface.

这篇关于Django视图流-定义API流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆