Skip to content

Add StartWorkflowMixin #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion joeflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .conf import settings
from .typing import HUMAN, MACHINE
from .utils import NoDashDiGraph
from .views import StartWorkflowMixin

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -139,7 +140,7 @@
urls = []
for name, node in cls.get_nodes():
if isinstance(node, View):
if isinstance(node, BaseCreateView):
if isinstance(node, (BaseCreateView, StartWorkflowMixin)):
route = f"{name}/"
else:
route = f"{name}/<int:pk>/"
Expand Down
4 changes: 2 additions & 2 deletions joeflow/tasks/human.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from django.views import generic

from joeflow.views import TaskViewMixin
from joeflow.views import StartWorkflowMixin, TaskViewMixin

__all__ = (
"StartView",
"UpdateView",
)


class StartView(TaskViewMixin, generic.CreateView):
class StartView(TaskViewMixin, StartWorkflowMixin, generic.CreateView):
"""
Start a new workflow by a human with a view.

Expand Down
17 changes: 17 additions & 0 deletions joeflow/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ def get_template_names(self):
return names


class StartWorkflowMixin:
"""
View-mixin to create a start workflow.

Example:
class MyStartWorkflowView(StartWorkflowMixin, TaskViewMixin, View):
def post(self, request, *args, **kwargs):
try:
data = json.loads(request.body)
workflow_id = self.start_workflow(data)
except Exception as e:
return HttpResponseBadRequest("Failed to start workflow")

return JsonResponse({'message': 'Workflow started successfully.', 'id': workflow_id}, status=201)
"""


class TaskViewMixin(WorkflowTemplateNameViewMixin, RevisionMixin):
name = None
path = ""
Expand Down