Skip to content

Commit

Permalink
added back line
Browse files Browse the repository at this point in the history
  • Loading branch information
gjelsas authored and Pierre-Sassoulas committed Oct 29, 2024
1 parent 1824d45 commit 5b76cd7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions survey/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


class ResponseForm(models.ModelForm):

FIELDS = {
Question.TEXT: forms.CharField,
Question.SHORT_TEXT: forms.CharField,
Expand Down Expand Up @@ -304,16 +305,15 @@ def clean_choices(self, s):
value = self.cleaned_data
print(value)
for q in s.questions.all():
# TODO check for type of question!
question = q
max = question.maximum_choices
print("Max: %d" % max)
if value.get(f"question_{question.id}"):
"""Only if some answers are checked."""
number_of_choices = len(value.get(f"question_{question.id}"))
print("Ausgewaehlte Antworten: %d" % number_of_choices)
if number_of_choices > max:
LOGGER.info("Selected more Answers than allowed! Maximum is %d.", max)
# TODO create a meaningful dialog for the user!
return None
if q.type in ["select-multiple"]:
# Only for SELECT_MULTIPlE
question = q
max = question.maximum_choices
if value.get(f"question_{question.id}"):
"""Only if some answers are checked at all."""
number_of_choices = len(value.get(f"question_{question.id}"))
if number_of_choices > max:
LOGGER.info("Selected more Answers than allowed! Maximum is %d.", max)
# TODO create a meaningful dialog for the user!
return None
return value

0 comments on commit 5b76cd7

Please sign in to comment.