From 1110150ea687b4c17f2e6d6566ac6a21e63d1187 Mon Sep 17 00:00:00 2001 From: Dan Braghis <dan.braghis@torchbox.com> Date: Mon, 18 Jun 2018 14:57:43 +0100 Subject: [PATCH] Redirect to determination form and prepopulate determination when using determination transition --- opentech/apply/determinations/forms.py | 16 ++++++++++++++-- opentech/apply/funds/views.py | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/opentech/apply/determinations/forms.py b/opentech/apply/determinations/forms.py index 6bbddbb1d..017a56243 100644 --- a/opentech/apply/determinations/forms.py +++ b/opentech/apply/determinations/forms.py @@ -1,7 +1,8 @@ from django import forms from django.core.exceptions import NON_FIELD_ERRORS, ValidationError -from .models import Determination, DETERMINATION_CHOICES +from opentech.apply.funds.workflow import DETERMINATION_RESPONSE_TRANSITIONS +from .models import Determination, DETERMINATION_CHOICES, UNDETERMINED, UNAPPROVED, APPROVED from opentech.apply.utils.options import RICH_TEXT_WIDGET @@ -36,6 +37,8 @@ class BaseDeterminationForm(forms.ModelForm): self.submission = kwargs.pop('submission') super().__init__(*args, **kwargs) + self.fields['determination'].initial = self.get_determination_default() + if self.draft_button_name in self.data: for field in self.fields.values(): field.required = False @@ -60,12 +63,21 @@ class BaseDeterminationForm(forms.ModelForm): super().save() + def get_determination_default(self): + action = self.request.GET.get('action') + if action in DETERMINATION_RESPONSE_TRANSITIONS: + if '_more_info' in action: + return UNDETERMINED + elif '_accepted' in action: + return APPROVED + return UNAPPROVED + class ConceptDeterminationForm(BaseDeterminationForm): determination = forms.ChoiceField( choices=DETERMINATION_CHOICES, label='Determination', - help_text='Do you recommend requesting a proposal based on this concept note?' + help_text='Do you recommend requesting a proposal based on this concept note?', ) determination_message = RichTextField( label='Determination message', diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 22c75a1a9..75704ac20 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -1,6 +1,7 @@ from django.contrib.auth.decorators import login_required from django.core.exceptions import PermissionDenied from django.http import HttpResponseRedirect +from django.urls import reverse_lazy from django.utils.decorators import method_decorator from django.views.generic import UpdateView @@ -15,6 +16,7 @@ from opentech.apply.activity.views import ( DelegatedViewMixin, ) from opentech.apply.activity.models import Activity +from opentech.apply.funds.workflow import DETERMINATION_RESPONSE_TRANSITIONS from opentech.apply.review.views import ReviewContextMixin from opentech.apply.users.decorators import staff_required from opentech.apply.utils.views import DelegateableView, ViewDispatcher @@ -70,6 +72,12 @@ class ProgressSubmissionView(DelegatedViewMixin, UpdateView): context_name = 'progress_form' def form_valid(self, form): + action = form.cleaned_data.get('action') + # Defer to the determination form for any of the determination transitions + if action in DETERMINATION_RESPONSE_TRANSITIONS: + return HttpResponseRedirect(reverse_lazy('apply:submissions:determinations:form', args=(form.instance.id,))\ + + "?action=" + action) + response = super().form_valid(form) return self.progress_stage(form.instance) or response -- GitLab