-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathflows.py
74 lines (62 loc) · 2.26 KB
/
flows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from django.utils.translation import gettext_lazy as _
from viewflow import this
from viewflow.contrib import celery
from viewflow.workflow import flow, lock, act
from viewflow.workflow.flow import views
from .models import HelloWorldProcess
from .tasks import send_hello_world_request
class HelloWorldFlow(flow.Flow):
"""
Flow for sending hello world message requests.
This process demonstrates a flow for sending hello world message requests
that require supervisor approval before being sent.
"""
process_class = HelloWorldProcess
process_title = _("Hello world")
process_description = _(
"This process enables the user to send a message to the world, and request approval from a supervisor."
)
process_summary_template = _("Send '{{ process.text }}' message to the world")
process_result_template = _(
"{% if process.approved %}"
"Successfully sent '{{ process.text }}' message to the world"
"{% else %}Message was rejected"
"{% endif %}"
)
lock_impl = lock.select_for_update_lock
start = (
flow.Start(views.CreateProcessView.as_view(fields=["text"]))
.Annotation(title=_("New message"))
.Permission(auto_create=True)
.Next(this.approve)
)
approve = (
flow.View(views.UpdateProcessView.as_view(fields=["approved"]))
.Annotation(
title=_("Approval Request"),
description=_("Presents the message to a supervisor for approval."),
summary_template=_("Message review required"),
result_template=_(
"Message was {{ process.approved|yesno:'Approved,Rejected' }}"
),
)
.Permission(auto_create=True)
.Next(this.check_approve)
)
check_approve = (
flow.If(act.process.approved)
.Annotation(title=_("Approvement check"))
.Then(this.send)
.Else(this.end)
)
send = (
celery.Job(send_hello_world_request)
.Annotation(title=_("Send message"))
.Next(this.end)
)
end = flow.End().Annotation(
title=_("End"),
summary_template=(
"{% load i18n %}{% if process.approved %}{% trans 'Completed' %}{% else %}{% trans 'Rejected'%}{% endif %}"
),
)