From 8d3a69bd424232781463c2963c9031ab9995e167 Mon Sep 17 00:00:00 2001 From: Wes Appler Date: Wed, 3 Jan 2024 14:47:33 -0500 Subject: [PATCH] Enabled validation of determination draft saving --- hypha/apply/determinations/forms.py | 9 ++++++--- .../determinations/base_determination_form.html | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hypha/apply/determinations/forms.py b/hypha/apply/determinations/forms.py index 9a337cf291..1315c7d45c 100644 --- a/hypha/apply/determinations/forms.py +++ b/hypha/apply/determinations/forms.py @@ -520,8 +520,11 @@ def __init__( self.fields[field].disabled = True if self.draft_button_name in self.data: - for field in self.fields.values(): - field.required = False + # A determination must be set for saving a draft, + # this forces outcome to be validated. + unreq_fields = [name for name in self.fields if name != "outcome"] + for name in unreq_fields: + self.fields[name].required = False if edit: self.fields.pop("outcome") @@ -548,8 +551,8 @@ def save(self, commit=True): self.instance.outcome = int( self.cleaned_data[self.instance.determination_field.id] ) - # Need to catch KeyError as outcome field would not exist in case of edit. except KeyError: + # Need to catch KeyError as outcome field would not exist in case of edit. pass self.instance.is_draft = self.draft_button_name in self.data self.instance.form_data = self.cleaned_data["form_data"] diff --git a/hypha/apply/determinations/templates/determinations/base_determination_form.html b/hypha/apply/determinations/templates/determinations/base_determination_form.html index d575ce5492..6d59488bcc 100644 --- a/hypha/apply/determinations/templates/determinations/base_determination_form.html +++ b/hypha/apply/determinations/templates/determinations/base_determination_form.html @@ -39,7 +39,7 @@

{{ value }}

{% block form_buttons %}
{% if form.draft_button_name %} - + {% endif %}