Skip to content

Commit 68ecec3

Browse files
committed
enable per question mandatory fields
1 parent cced64c commit 68ecec3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

crowdsourcer/forms.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ class ResponseForm(ModelForm):
5050
mandatory_if_no = ["private_notes"]
5151
mandatory_if_response = ["public_notes", "page_number", "evidence", "private_notes"]
5252

53+
def get_mandatory_fields(self):
54+
mandatory_fields = settings.MANDATORY_FIELDS.get(self.session.label, {})
55+
56+
if mandatory_fields.get(self.question_obj.number_and_part):
57+
mandatory_fields = mandatory_fields[self.question_obj.number_and_part]
58+
59+
if mandatory_fields.get("mandatory_if_response") is not None:
60+
self.mandatory_if_response = mandatory_fields["mandatory_if_response"]
61+
62+
if mandatory_fields.get("mandatory_if_no") is not None:
63+
self.mandatory_if_no = mandatory_fields["mandatory_if_no"]
64+
5365
def __init__(self, *args, **kwargs):
5466
super().__init__(*args, **kwargs)
5567

@@ -79,13 +91,7 @@ def __init__(self, *args, **kwargs):
7991
if form_hints.get(field):
8092
self.fields[field].help_text = form_hints[field]
8193

82-
mandatory_fields = settings.MANDATORY_FIELDS.get(self.session.label, {})
83-
84-
if mandatory_fields.get("mandatory_if_response") is not None:
85-
self.mandatory_if_response = mandatory_fields["mandatory_if_response"]
86-
87-
if mandatory_fields.get("mandatory_if_no") is not None:
88-
self.mandatory_if_no = mandatory_fields["mandatory_if_no"]
94+
self.get_mandatory_fields()
8995

9096
def clean_page_number(self):
9197
page_number = self.cleaned_data["page_number"]

0 commit comments

Comments
 (0)