I'm building an approval workflow using django-viewflow and django-material.
A key component of the workflow is for the end user to fill in a lengthy form and eventually submit it for review and approval.
What I want
My users will expect to be able to save and continue editing, so that they can fill in the form half way, save their progress, and come back later to complete the form filling. Only then they'll want to submit the form.
This is a standard feature in the Django admin.
What I've found
In the default task.html template, django-viewflow offers two submit buttons (source):
<button type="submit" name="_continue" class="btn btn-flat">{% trans 'Done and continue on this process' %}</button>
<button type="submit" name="_done" class="btn primary white-text">{% trans 'Done' %}</button>
The official docs are pretty slim on the difference between these two tasks.
"Done and continue" marks the current task as done and activates the next task (which as a user I want to do by default, other than "save and continue editing").
"Done" seems to mark the current task as done, but doesn't proceed to the next task, which requires some awkward self-assigning to proceed. I can see how a user can get confused here.
What I've tried
I've read the viewflow documentation, especially on activation but couldn't find any explanation on _continue
vs _done
.
Searching the code bases of django-viewflow (incl frontend) and django-material, I found the flow.html
template. _continue
is referenced from tasks.py
and utils.py
. _done
is not referenced anywhere I could find.
flow/view/utils.py
(source) seems to point to the next task (if any assigned to user) on completion of a task.
I can see a viewflow GH issue from 2016 on this providing an example mixin (credits GH @codingjoe):
class SavableViewMixin:
@Activation.status.transition(source=STATUS.PREPARED, target=STATUS.ASSIGNED)
def save_task(self):
self.task.save()
def activation_done(self, *args, **kwargs):
if '_save' in self.request.POST:
self.save_task()
else:
self.done()
def message_complete(self):
if '_save' not in self.request.POST:
super(SavableViewMixin, self).message_complete()
def get_success_url(self):
if '_save' in self.request.POST:
return self.request.get_full_path()
return super(SavableViewMixin, self).get_success_url()
This snippet doesn't work anymore, which is expected since it's referencing a six years old viewflow version. I would need to dig into the Activation/Task API to figure out exactly what to override.
The issue also references a now removed example "viewflow_pause" in the cookbook.
Where I'm stuck
Is there a canonical way to provide a "save and continue editing" button to each task?
Is the "viewflow_pause" example still around somewhere?
If I have to reinvent this myself, what should I override?