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 0000000000000000000000000000000000000000..989accc20359c06a95869b81f90d99908054f380 --- /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 1d9f10a6f0e3a9dafa8228f7316fbec523395ff1..04dcce068c2af73336f4e7faf0f9257ee7f29940 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 0000000000000000000000000000000000000000..60b2ca2332e499477ca07a71b6dbae21dd88d399 --- /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)