diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 6c8b7772fd58fd987d5106335eb3ace9e63f5586..92775fc414668da260c35d42bcb2935efb80542c 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -16,7 +16,7 @@ from django.urls import reverse from django.utils.text import mark_safe, slugify from django.utils.translation import ugettext_lazy as _ -from django_fsm import FSMField, transition +from django_fsm import FSMField, transition, RETURN_VALUE from modelcluster.fields import ParentalKey, ParentalManyToManyField from wagtail.admin.edit_handlers import ( FieldPanel, @@ -553,6 +553,17 @@ class ApplicationSubmission(WorkflowHelpers, BaseStreamForm, AbstractFormSubmiss objects = ApplicationSubmissionQueryset.as_manager() + def not_progressed(self): + return not self.next and self.workflow != WORKFLOWS['single'] + + @transition( + status, source='*', + target=RETURN_VALUE(INITIAL_STATE, 'draft_proposal'), + conditions=[not_progressed] + ) + def restart_stage(self): + return self.workflow.stages.index(self.stage)[INITIAL_STATE, 'draft_proposal'] + @property def stage(self): return self.phase.stage