From 9d8bad285daa63c5a401f67751c7c1183cb354b2 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Fri, 28 Sep 2018 12:05:29 +0100 Subject: [PATCH] Make sure we get the new form_fields for the transition --- opentech/apply/funds/models/submissions.py | 11 ++++++++++- opentech/apply/funds/tests/test_views.py | 18 ++++++++++++++++++ opentech/apply/funds/workflow.py | 13 +++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py index 4bf6246b7..6d7f9b446 100644 --- a/opentech/apply/funds/models/submissions.py +++ b/opentech/apply/funds/models/submissions.py @@ -32,6 +32,7 @@ from ..workflow import ( DETERMINATION_RESPONSE_PHASES, get_review_statuses, INITIAL_STATE, + PHASES, review_statuses, STAGE_CHANGE_ACTIONS, UserPermissions, @@ -397,10 +398,18 @@ class ApplicationSubmission( return getattr(self.page.specific, attribute) def progress_application(self, **kwargs): + target = None + for phase in STAGE_CHANGE_ACTIONS: + transition = self.get_transition(phase) + if can_proceed(transition): + target = PHASES[phase].stage + if not target: + raise ValueError('Incorrect State for transition') + submission_in_db = ApplicationSubmission.objects.get(id=self.id) self.id = None - self.form_fields = self.get_from_parent('get_defined_fields')(self.stage) + self.form_fields = self.get_from_parent('get_defined_fields')(target) self.live_revision = None self.draft_revision = None diff --git a/opentech/apply/funds/tests/test_views.py b/opentech/apply/funds/tests/test_views.py index a1614e477..6888d4d74 100644 --- a/opentech/apply/funds/tests/test_views.py +++ b/opentech/apply/funds/tests/test_views.py @@ -18,6 +18,7 @@ from opentech.apply.users.tests.factories import ( SuperUserFactory, UserFactory, ) +from opentech.apply.utils.testing import make_request from opentech.apply.utils.testing.tests import BaseViewTestCase from ..models import ApplicationRevision @@ -92,6 +93,23 @@ class TestStaffSubmissionView(BaseSubmissionViewTestCase): url = self.url_from_pattern('funds:submissions:determinations:form', kwargs={'submission_pk': submission.id}) self.assertRedirects(response, f"{url}?action=invited_to_proposal") + def test_new_form_after_progress(self): + submission = ApplicationSubmissionFactory(status='invited_to_proposal', workflow_stages=2, lead=self.user) + stage = submission.stage + DeterminationFactory(submission=submission, accepted=True) + + request = make_request(self.user, method='get', site=submission.page.get_site()) + submission.progress_stage_when_possible(self.user, request) + + submission = self.refresh(submission) + new_stage = submission.stage + + self.assertNotEqual(stage, new_stage) + + get_forms = submission.get_from_parent('get_defined_fields') + self.assertEqual(submission.form_fields, get_forms(new_stage)) + self.assertNotEqual(submission.form_fields, get_forms(stage)) + def test_cant_progress_stage_if_not_lead(self): submission = ApplicationSubmissionFactory(status='concept_review_discussion', workflow_stages=2) self.post_page(submission, {'form-submitted-progress_form': '', 'action': 'invited_to_proposal'}) diff --git a/opentech/apply/funds/workflow.py b/opentech/apply/funds/workflow.py index 95039d767..e580c5808 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -429,7 +429,7 @@ WORKFLOWS = { } -PHASES = list(itertools.chain.from_iterable(workflow.items() for workflow in WORKFLOWS.values())) +PHASES = dict(itertools.chain.from_iterable(workflow.items() for workflow in WORKFLOWS.values())) def get_stage_change_actions(): @@ -449,11 +449,12 @@ STAGE_CHANGE_ACTIONS = get_stage_change_actions() STATUSES = defaultdict(set) -for key, value in PHASES: +for key, value in PHASES.items(): STATUSES[value.display_name].add(key) + active_statuses = [ - status for status, _ in PHASES + status for status in PHASES if 'accepted' not in status and 'rejected' not in status and 'invited' not in status ] @@ -461,7 +462,7 @@ active_statuses = [ def get_review_statuses(user=None): reviews = set() - for phase_name, phase in PHASES: + for phase_name, phase in PHASES.items(): if 'review' in phase_name and 'discussion' not in phase_name: if user is None: reviews.add(phase_name) @@ -472,7 +473,7 @@ def get_review_statuses(user=None): review_statuses = get_review_statuses() -DETERMINATION_PHASES = list(phase_name for phase_name, _ in PHASES if '_discussion' in phase_name) +DETERMINATION_PHASES = list(phase_name for phase_name in PHASES if '_discussion' in phase_name) DETERMINATION_RESPONSE_PHASES = [ 'post_review_discussion', 'concept_review_discussion', @@ -482,7 +483,7 @@ DETERMINATION_RESPONSE_PHASES = [ def get_determination_transitions(): transitions = {} - for phase_name, phase in PHASES: + for phase_name, phase in PHASES.items(): for transition_name in phase.transitions: if 'accepted' in transition_name: transitions[transition_name] = 'accepted' -- GitLab