diff --git a/opentech/apply/categories/blocks.py b/opentech/apply/categories/blocks.py index ffa193a4e5112d43bbf815ea2c0226d1420fe0a1..02359dc54c454236183c6407d962f59fc8e4c687 100644 --- a/opentech/apply/categories/blocks.py +++ b/opentech/apply/categories/blocks.py @@ -77,11 +77,12 @@ class CategoryQuestionBlock(OptionalFormFieldBlock): def render(self, value, context): data = context['data'] category = value['category'] - context['data'] = category.options.filter(id__in=data).values_list('value', flat=True) + if data: + context['data'] = category.options.filter(id__in=data).values_list('value', flat=True) return super().render(value, context) def get_searchable_content(self, value, data): return None def no_response(self): - return None + return ['No Response'] diff --git a/opentech/apply/categories/tests/test_blocks.py b/opentech/apply/categories/tests/test_blocks.py index fa8bee4ea1240337661588cc3ccbc5215c840076..c436308019ffc4e913bc109e999e2f6e576de9e4 100644 --- a/opentech/apply/categories/tests/test_blocks.py +++ b/opentech/apply/categories/tests/test_blocks.py @@ -52,3 +52,7 @@ class TestCategoryQuestionBlock(TestCase): field.choices, [(option.id, option.value) for option in self.category.options.all()] ) + + def test_can_render_if_no_response(self): + display = self.block.render({'category': self.category}, {'data': None}) + self.assertIn(self.block.no_response()[0], display) diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py index 4bf6246b7df78d5de57d44de134a296d54ca77b1..646422bc08ced60de8d222412a6e76843a3bf54f 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,20 @@ 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): + # We convert to dict as not concerned about transitions from the first phase + # See note in workflow.py + target = dict(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 a1614e4777ae14cdf27827b757dee36b66550375..6888d4d7475d0fcb86dda61b1b2957b772aefb0d 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 95039d7678f54e9389160ac820064708cfb77cfa..b0e408b6878faf1a158d087d5a4e030dc6fff15a 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -429,6 +429,8 @@ WORKFLOWS = { } +# This is not a dictionary as the keys will clash for the first phase of each workflow +# We cannot find the transitions for the first stage in this instance PHASES = list(itertools.chain.from_iterable(workflow.items() for workflow in WORKFLOWS.values()))