From 2ca501e2235260252df4109ce1596d0378c3d51c Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Wed, 14 Feb 2018 11:31:11 +0000
Subject: [PATCH] Update the submission model to have a workflow and status

---
 ...0_add_workflow_and_status_to_submission.py | 30 +++++++++++++++++++
 opentech/apply/funds/models.py                | 25 +++++++++++-----
 2 files changed, 48 insertions(+), 7 deletions(-)
 create mode 100644 opentech/apply/funds/migrations/0020_add_workflow_and_status_to_submission.py

diff --git a/opentech/apply/funds/migrations/0020_add_workflow_and_status_to_submission.py b/opentech/apply/funds/migrations/0020_add_workflow_and_status_to_submission.py
new file mode 100644
index 000000000..9d64d2adf
--- /dev/null
+++ b/opentech/apply/funds/migrations/0020_add_workflow_and_status_to_submission.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.8 on 2018-02-14 11:29
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('funds', '0019_protect_submission'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='applicationsubmission',
+            options={},
+        ),
+        migrations.AddField(
+            model_name='applicationsubmission',
+            name='status',
+            field=models.CharField(default='', max_length=254),
+            preserve_default=False,
+        ),
+        migrations.AddField(
+            model_name='applicationsubmission',
+            name='workflow',
+            field=models.CharField(choices=[('single', 'Single Stage'), ('double', 'Two Stage')], default='single', max_length=100),
+        ),
+    ]
diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py
index 2b2b7833b..7e1e19c2c 100644
--- a/opentech/apply/funds/models.py
+++ b/opentech/apply/funds/models.py
@@ -91,9 +91,9 @@ class SubmittableStreamForm(AbstractStreamForm):
         return kwargs
 
 
-class WorkflowStreamForm(AbstractStreamForm):
+class WorkflowHelpers(models.Model):
     """
-    Defines the common methods and fields for working with Workflows
+    Defines the common methods and fields for working with Workflows within Django models
     """
     class Meta:
         abstract = True
@@ -105,14 +105,22 @@ class WorkflowStreamForm(AbstractStreamForm):
 
     workflow = models.CharField(choices=WORKFLOWS.items(), max_length=100, default='single')
 
-    def get_defined_fields(self):
-        # Only return the first form, will need updating for when working with 2 stage WF
-        return self.forms.all()[0].fields
-
     @property
     def workflow_class(self):
         return WORKFLOW_CLASS[self.get_workflow_display()]
 
+
+class WorkflowStreamForm(WorkflowHelpers, AbstractStreamForm):
+    """
+    Defines the common methods and fields for working with Workflows within Wagtail pages
+    """
+    class Meta:
+        abstract = True
+
+    def get_defined_fields(self):
+        # Only return the first form, will need updating for when working with 2 stage WF
+        return self.forms.all()[0].fields
+
     content_panels = AbstractStreamForm.content_panels + [
         FieldPanel('workflow'),
         InlinePanel('forms', label="Forms"),
@@ -412,12 +420,15 @@ class JSONOrderable(models.QuerySet):
         return super().order_by(*field_ordering)
 
 
-class ApplicationSubmission(AbstractFormSubmission):
+class ApplicationSubmission(WorkflowHelpers, AbstractFormSubmission):
     form_data = JSONField(encoder=DjangoJSONEncoder)
     page = models.ForeignKey('wagtailcore.Page', on_delete=models.PROTECT)
     round = models.ForeignKey('wagtailcore.Page', on_delete=models.PROTECT, related_name='submissions', null=True)
     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True)
 
+    # Workflow inherited from WorkflowHelpers
+    status = models.CharField(max_length=254)
+
     objects = JSONOrderable.as_manager()
 
     def get_data(self):
-- 
GitLab