Process Views outside viewflow.frontend

余生长醉 提交于 2019-12-01 10:33:21

The Viewflow views need to be parametrized by flow_class and flow_task instance. So you can include a start view as following::

url('^start/', CreateProcessView.as_view(), {
     'flow_class': MyFlow,
     'flow_task': MyFlow.start})

To add a task view URL config, you need to use process_pk and task_pk parameters

url('^(?P<process_pk>\d+)/approve/(?P<task_pk>\d+)/', ApproveView.as_view(), {
     'flow_class': MyFlow,
     'flow_task': MyFlow.approve
})

For each node, you also can enable detail, and various actions URLs, ex:

url('^(?P<process_pk>\d+)/approve/(?P<task_pk>\d+)/detail/', DetailTaskView.as_view(), {
     'flow_class': MyFlow,
     'flow_task': MyFlow.approve
}),
url('^(?P<process_pk>\d+)/approve/(?P<task_pk>\d+)/cancel/', CancelTaskView.as_view(), {
     'flow_class': MyFlow,
     'flow_task': MyFlow.approve
}),

All of that's a big cumbersome.

Recommended way

You can just include Flow.instance.urls that contains all URLs collected and ready for inclusion into an URL config.

url('^myflow', include(MyFlow.instance.urls, namespace='myflow'))

And at the last, to enable task list views, you can put URL entries manually, ex

url('^myflow/inbox/', TaskListView.as_view(), {
    'flow_class': MyFlow}, name="tasks")

or just use as viewflow.flow.viewset.FlowViewSet class

myflow_urls = FlowViewSet(MyFlow).urls

urlpatterns = [
    url(r'^myflow/', include(myflow_urls, namespace='myflow'))
]

This is the recommended way to include viewflow URLs into a django URL Config. To customize views used in that URL config, you can subclass the FlowViewSet class and provide views in the nodes definition, ex

class MyFlow(Flow):
    start = flow.Start(detail_view_class=MyDetailTaskView)

For the sample usage, you can checkout the Viewflow Custom UI cookbook example - https://github.com/viewflow/cookbook/tree/master/custom_ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!