File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 1919from .conf import settings
2020from .typing import HUMAN , MACHINE
2121from .utils import NoDashDiGraph
22+ from .views import StartWorkflowMixin
2223
2324logger = 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 , StartWorkflowMixin ) ):
143144 route = f"{ name } /"
144145 else :
145146 route = f"{ name } /<int:pk>/"
Original file line number Diff line number Diff line change 22
33from 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
Original file line number Diff line number Diff line change @@ -29,6 +29,22 @@ def get_template_names(self):
2929 return names
3030
3131
32+ class StartWorkflowMixin :
33+ """
34+ Use this mixin to create a start workflow with a view. Example:
35+
36+ class MyStartWorkflowView(StartWorkflowMixin, TaskViewMixin, View):
37+ def post(self, request, *args, **kwargs):
38+ try:
39+ data = json.loads(request.body)
40+ workflow_id = self.start_workflow(data)
41+ except Exception as e:
42+ return HttpResponseBadRequest("Failed to start workflow")
43+
44+ return JsonResponse({'message': 'Workflow started successfully.', 'id': workflow_id}, status=201)
45+ """
46+
47+
3248class TaskViewMixin (WorkflowTemplateNameViewMixin , RevisionMixin ):
3349 name = None
3450 path = ""
You can’t perform that action at this time.
0 commit comments