diff --git a/opentech/apply/determinations/forms.py b/opentech/apply/determinations/forms.py index 6bbddbb1d66143b74d54562b2f0b3f4340be1538..017a56243e718a7d9470c3f6eab06c07fc5dcbda 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 22c75a1a9956fe6195f5b4c375cd9ae913f6636b..75704ac20fcf95b4a0bda092a74c885c10348420 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