0

我最近遇到了 Django 的 Viewflow 库,它似乎是一个非常强大的工具,可用于创建复杂的工作流。

我的应用程序是一个简单的票务系统,工作流是通过创建票证开始的,然后用户应该能够通过 CRUD 页面创建零个或多个与票证相关联的工作日志,类似于标准的 Django 管理员 change_list/detail .

列表视图的模板应该是什么样的?我想将 UI 集成到图书馆的前端。

该流程清楚地利用了以下视图:

1) 为工单创建视图

2a) 工作日志的 ListView,模板具有控件“返回”、“添加”(转到步骤 2b)、“完成”(转到步骤 3)。

2b) 为工作日志创建视图

3) 结束

代码:

模型.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)

视图.py:

class WorkLogListView(FlowListMixin, ListView):

    model = WorkLog


class WorkLogCreateView(FlowMixin, CreateView):

    model = WorkLog
    fields = '__all__'

流.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()
4

1 回答 1

0

您可以在不同的视图中或在同一视图中处理它,只是不要调用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})
于 2017-07-25T12:07:04.947 回答