From b30d1a7304e1ea4131bfb3e5966a1e5e22ea348b Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Tue, 19 Dec 2017 12:17:06 +0000
Subject: [PATCH] Add workflow and test we can get the class from the fund

---
 .../migrations/0003_add_workflow_to_fund.py   | 20 +++++++++++++++++++
 opentech/apply/models.py                      | 12 +++++++++--
 opentech/apply/tests/test_models.py           | 11 ++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 opentech/apply/migrations/0003_add_workflow_to_fund.py
 create mode 100644 opentech/apply/tests/test_models.py

diff --git a/opentech/apply/migrations/0003_add_workflow_to_fund.py b/opentech/apply/migrations/0003_add_workflow_to_fund.py
new file mode 100644
index 000000000..989accc20
--- /dev/null
+++ b/opentech/apply/migrations/0003_add_workflow_to_fund.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.7 on 2017-12-19 12:09
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('apply', '0002_fund_workflow'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='fund',
+            name='workflow',
+            field=models.CharField(choices=[('single', 'Single Stage'), ('double', 'Two Stage')], default='single', max_length=100),
+        ),
+    ]
diff --git a/opentech/apply/models.py b/opentech/apply/models.py
index 1d9f10a6f..04dcce068 100644
--- a/opentech/apply/models.py
+++ b/opentech/apply/models.py
@@ -8,6 +8,10 @@ from opentech.utils.models import SocialFields, ListingFields
 
 from .workflow import SingleStage, DoubleStage
 
+WORKFLOW_CLASS = {
+    SingleStage.name: SingleStage,
+    DoubleStage.name: DoubleStage,
+}
 
 class ApplyHomePage(Page, SocialFields, ListingFields):
     # Only allow creating HomePages at the root level
@@ -32,9 +36,13 @@ class ApplyHomePage(Page, SocialFields, ListingFields):
 class FundPage(Page):
     parent_page_types = [ApplyHomePage]
     WORKFLOWS = (
-        ('single', SingleStage),
-        ('double', DoubleStage),
+        ('single', SingleStage.name),
+        ('double', DoubleStage.name),
     )
 
     name = models.CharField(max_length=60)
     workflow = models.CharField(choices=WORKFLOWS, max_length=100, default=WORKFLOWS[0][0])
+
+    @property
+    def workflow_class(self):
+        return WORKFLOW_CLASS[self.get_workflow_display()]
diff --git a/opentech/apply/tests/test_models.py b/opentech/apply/tests/test_models.py
new file mode 100644
index 000000000..60b2ca233
--- /dev/null
+++ b/opentech/apply/tests/test_models.py
@@ -0,0 +1,11 @@
+from django.test import TestCase
+
+from opentech.apply.models import Fund
+from opentech.apply.workflow import SingleStage
+
+
+class TestFundModel(TestCase):
+    def test_can_access_workflow_class(self):
+        fund = Fund.objects.create(name='Internet Freedom Fund')
+        self.assertEqual(fund.workflow, 'single')
+        self.assertEqual(fund.workflow_class, SingleStage)
-- 
GitLab