Summary
I am developing a web application for learning Django (python 3.4 and Django 1.6.10). The web application has complex and frequently updated workflows. I decided to integrate the Django-Viewflow library ( https://github.com/viewflow/viewflow/ ), because it seems to be a very convenient way to process workflows and does not include logic workflow using application models.
In this case, I created a workflow for collecting copyright information and copyrights using the Django-Viewflow library. The workflow should begin every time the author is added to the book.
My problem
The documentation provides step-by-step instructions for integrating the end-to-end worklfow solution (frontend and backend). My problem is that it is difficult for me to manage the workflow programmatically (in particular, from the book).
Application description
I have a book model (main model) with many relationships to authors.
MYAPP / models.py
class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField()
Workflow components:
myFlow / models.py
from viewflow.models import Process class AuthorInvitation(process) consent_confirmed = models.BooleanField(default=False) signature = models.CharField(max_length=150)
myFlow / flows.py
from viewflow import flow from viewflow.base import this, Flow from viewflow.contrib import celery from viewflow.views import StartProcessView, ProcessView from . import models, tasks class AuthorInvitationFlow(Flow): process_cls = models.AuthorInvitation start = flow.Start(StartProcessView) \ .Permission(auto_create=True) \ .Next(this.notify) notify = celery.Job(tasks.send_authorship_request) \ .Next(this.approve) approve = flow.View(ProcessView, fields=["confirmed","signature"]) \ .Permission(auto_create=True) \ .Next(this.check_approve) check_approve = flow.If(cond=lambda p: p.confirmed) \ .OnTrue(this.send) \ .OnFalse(this.end) send = celery.Job(tasks.send_authorship) \ .Next(this.end) end = flow.End()
Question
How can you programmatically manage the workflow process (activate, confirm steps, repeat steps, cancel the process ...)? I tried to delve into the code of the library. It seems that class activate contains the correct method, but is not sure how everything should be organized.
Thanks in advance!
python workflow django django-viewflow
protactinium
source share