From: Jan Szejko Date: Mon, 19 Nov 2018 13:01:47 +0000 (+0100) Subject: force non-empty answers X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/4aa1adece1b82e31529874780039bd48ef25c335?ds=sidebyside force non-empty answers --- diff --git a/wtem/forms.py b/wtem/forms.py index a434854..08a1e19 100644 --- a/wtem/forms.py +++ b/wtem/forms.py @@ -61,6 +61,8 @@ class WTEMSingleForm(forms.ModelForm): if exercise_id != str(exercise['id']): raise ValueError('wrong exercise id') for answer in posted_answers.values(): + if not answer.get('closed_part', True): + raise ValueError('no answer') answers[exercise_id] = answer submission.answers = json.dumps(answers) submission.save() diff --git a/wtem/views.py b/wtem/views.py index be78eb5..1d1074c 100644 --- a/wtem/views.py +++ b/wtem/views.py @@ -132,9 +132,11 @@ def form_single(request, submission_id, key): except ValueError as e: if e.message == 'wrong exercise id': messages.error(request, u'Próba wysłania odpowiedzi ponownie lub poza kolejnością') + elif e.message == 'no answer': + messages.error(request, u'Wybierz przynajmniej jedną odpowiedź') return HttpResponseRedirect(reverse('wtem_form', kwargs={'submission_id': submission_id, 'key': key})) else: - raise Exception + raise Exception(u'Błędna wartość w formularzu') @cache_until_start