我使用django-viewflow来跟踪复杂的业务流程。为了避免使用过长的流类和flows.py文件,我希望将一个流提要到另一个流中。这个是可能的吗?
我尝试了下面的代码,但是Python抛出了一个NotImplemented异常。
class SecondFlow(Flow):
process_class = SecondProcess
start = (...)
class FirstFlow(Flow):
process_class = FirstProcess
start = (
flow.Start(
CreateProcessView,
fields=['foo']
).Next(SecondFlow.start)
)如果FirstFlow路由到SecondFlow的开头,那就太好了。
编辑:我尝试使用提供的建议和文档,但收到以下错误:'StartFunction‘对象没有'prepare’属性
下面是我的新代码。
from viewflow import flow, frontend
from viewflow.base import this, Flow
from viewflow.flow.views import CreateProcessView, UpdateProcessView
from .models import FirstProcess, SecondProcess
@frontend.register
class SecondFlow(Flow):
process_class = SecondProcess
start = flow.StartFunction(this.create_flow
).Next(this.enter_text)
def create_flow(self, activation, **kwargs):
activation.prepare()
activation.done()
enter_text = (
flow.View(
UpdateProcessView,
fields=['text']
).Next(this.end)
)
end = flow.End()
@frontend.register
class FirstFlow(Flow):
process_class = FirstProcess
start = (
flow.Start(
CreateProcessView,
fields=['text']
).Next(this.initiate_second_flow)
)
initiate_second_flow = (
flow.Handler(this.start_second_flow
).Next(this.end)
)
def start_second_flow(self, activation):
SecondFlow.start.run()
end = flow.End()第二个编辑:在我向SecondFlow的create_flow方法添加了一个装饰器之后,它就可以工作了。
from django.utils.decorators import method_decorator
...
@frontend.register
class SecondFlow(Flow):
process_class = SecondProcess
start = flow.StartFunction(this.create_flow
).Next(this.enter_text)
@method_decorator(flow.flow_start_func)
def create_flow(self, activation, **kwargs):
activation.prepare()
activation.done()
...发布于 2019-02-11 17:09:47
flow.Start是由用户调用并创建进程的启动视图的任务。视图可以有一些逻辑,通常,该逻辑依赖于request数据。因此,您不能在其他地方调用flow.StartView和flow.View,除非通过浏览器访问URL。
要以编程方式激活某些进程,需要使用flow.StartFunction - http://docs.viewflow.io/viewflow_core_node.html#viewflow.nodes.StartFunction
要从另一个流执行它,可以使用flow.Handler - http://docs.viewflow.io/viewflow_core_node.html#viewflow.nodes.Handler
https://stackoverflow.com/questions/54594364
复制相似问题