Skip to content

Commit b3336ed

Browse files
committed
Add StartWorkflowMixin
This allows to start new workflows from views that don't inherit from BaseCreateView. This is useful if you e.g. want to start a view from json input and don't need forms.
1 parent 94cd044 commit b3336ed

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

joeflow/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .conf import settings
2020
from .typing import HUMAN, MACHINE
2121
from .utils import NoDashDiGraph
22+
from .views import StartWorkflowMixin
2223

2324
logger = logging.getLogger(__name__)
2425

@@ -139,7 +140,7 @@ def urls(cls):
139140
urls = []
140141
for name, node in cls.get_nodes():
141142
if isinstance(node, View):
142-
if isinstance(node, BaseCreateView):
143+
if isinstance(node, BaseCreateView) | isinstance(node, StartWorkflowMixin):
143144
route = f"{name}/"
144145
else:
145146
route = f"{name}/<int:pk>/"

joeflow/tasks/human.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from django.views import generic
44

5-
from joeflow.views import TaskViewMixin
5+
from joeflow.views import TaskViewMixin, StartWorkflowMixin
66

77
__all__ = (
88
"StartView",
99
"UpdateView",
1010
)
1111

1212

13-
class StartView(TaskViewMixin, generic.CreateView):
13+
class StartView(TaskViewMixin, StartWorkflowMixin, generic.CreateView):
1414
"""
1515
Start a new workflow by a human with a view.
1616

joeflow/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def get_template_names(self):
2828
)
2929
return names
3030

31+
class StartWorkflowMixin():
32+
"""
33+
Use this mixin to create a start workflow with a view.
34+
"""
35+
pass
3136

3237
class TaskViewMixin(WorkflowTemplateNameViewMixin, RevisionMixin):
3338
name = None

0 commit comments

Comments
 (0)