我最近遇到了Django的Viewflow库,它似乎是创建复杂工作流的一个非常强大的工具。
我的应用程序是一个简单的票务系统,工作流程是通过创建票证启动的,那么用户应该能够通过CRUD页面创建零个或多个与票证相关的工作日志,类似于标准的Django admin change_list/detail。
列表视图的模板应该是什么样子的?我希望将UI集成到库的前端。
该流程清楚地利用了以下视图:
1)工单CreateView
2a)工作日志的ListView,模板有控件'back','add‘(转到步骤2b),'done’(转到步骤3)。
2b)用于WorkLog的CreateView
3)结束
代码:
models.py:
class TicketProcess(Process):
title = models.CharField(max_length=100)
category = models.CharField(max_length=150)
description = models.TextField(max_length=150)
planned = models.BooleanField()
worklogs = models.ForeignKey('WorkLog', null=True)
class WorkLog(models.Model):
ref = models.CharField(max_length=32)
description = models.TextField(max_length=150)views.py:
class WorkLogListView(FlowListMixin, ListView):
model = WorkLog
class WorkLogCreateView(FlowMixin, CreateView):
model = WorkLog
fields = '__all__'flows.py:
from .views import WorkLogCreateView
from .models import TicketProcess
@frontend.register
class TicketFlow(Flow):
process_class = TicketProcess
start = (
flow.Start(
CreateProcessView,
fields = ['title', 'category', 'description', 'planned']
).Permission(
auto_create=True
).Next(this.resolution)
)
add_worklog = (
flow.View(
WorkLogListView
).Permission(
auto_create=True
).Next(this.end)
)
end = flow.End()发布于 2017-07-25 20:07:05
您可以在不同的视图中处理,也可以在相同的视图中处理,只是不要在工作日志添加请求上调用activation.done。您可以通过检查request.POST数据中按下的按钮来完成此操作。
@flow.flow_view
def worklog_view(request):
request.activation.prepare(request.POST or None, user=request.user)
if '_logitem' in request.POST:
WorkLog.objects.create(...)
elif request.POST:
activation.done()
request.activation.done()
return redirect(get_next_task_url(request, request.activation.process))
return render(request, 'sometemplate.html', {'activation': request.activation})https://stackoverflow.com/questions/45143931
复制相似问题