要获取任务的 url,您只需要app_name(app_namespace), flow_namespace and flow_label
. 这里最具挑战性的项目是 flow_namespace(如果你没有使用前端 url)。要解决此问题,您可以使用从 FlowListMixin 的 ns_map 借用的地图。为项目中的每个流定义 flow_namespace。然后,您从上面确定流命名空间和 url_name。
ns_map = {'MyFlow':'flow_namespace', 'AnotherFlow':'flow_namespace2'}
# flow_namespace as defined in the urls.py
# e.g if you defined your flow urls as
# flow_urls = FlowViewSet(MyFlow).urls
# flow_urls2 = FLowViewSet(MyFlow2).urls
# urlpatterns = [url(r'flow_path/', include(flow_urls, name=flow_namespace)),
# url(r'flow_path2/', include(flow_urls2, name=flow_namespace2)),
# ]
# With this is included in the root_url as
# urlpatterns = [
# url(r'app/' include(app_urls, namespace='app_namespace')
#]
您需要像这样反转流程 reverse('app_name:flow_namespace:flow_label', kwargs={'process_pk':ppk, 'task_pk':tpk})
flow_class_name = task.process.flow_class.__name__
flow_namespace = ns_map.get(flow_class_name)
app_name = task.process.flow_class.__module__.split('.')[0]
flow_label = task.flow_task.name
url_name = "{}:{}:{}".format(app_name, flow_label, url_name)
然后你可以反转你的任务网址
url = reverse(url_name, kwargs={"task_pk", task.pk, "process_pk":task.flow_process.pk}
# If you know where you are you could use resolver match to determine
# the app namespace. Be Sure of this, see more of that [here][1]
注意:我假设您将应用程序命名为 app_name 如果它不同,您必须找到查找 app_names 命名空间的替代方法,但这应该不会太难。