I want to integrate processes, starting them etc., outside of the standard viewflow.frontend
. To do I have been trying to create a simple page where I can start a new process, but have been struggling to find a way to implement it.
One approach was to defined a url to url('^start_something, CustomStartView.as_view())
with CustomStartView
subclassing CreateProcessView
from viewflow.flow.views.start
. This ended in getting error after error, whenever I fixed one. I am quite sure now that this isn't the right way to do it, also because the View
is used as a parameter of the Flow
class itself and probably needs to be used differently than a common view.
What is the right way to do it?
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
来源:https://stackoverflow.com/questions/42277033/process-views-outside-viewflow-frontend