X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/3f387ec5d75ff85576e87649427cbdc1f14a95b8..000e4c425eb0f65533002e29e5b1b6ae1e60a77f:/wtem/forms.py?ds=sidebyside diff --git a/wtem/forms.py b/wtem/forms.py index 15c6503..a434854 100644 --- a/wtem/forms.py +++ b/wtem/forms.py @@ -49,11 +49,17 @@ class WTEMSingleForm(forms.ModelForm): submission = self.instance answers = submission.get_answers() posted_answers = json.loads(self.cleaned_data['answers']) - assert type(posted_answers) == dict, 'answers not dict' - assert len(posted_answers) == 1, 'answers not single' - exercise_id = posted_answers.keys()[0] + if type(posted_answers) != dict: + raise ValueError('answers not dict') + if len(posted_answers) != 1: + raise ValueError('answers not single') + exercise_id, answer = posted_answers.items()[0] + # multipost + if answers.get(exercise_id) == answer: + return i, exercise = submission.current_exercise() - assert exercise_id == str(exercise['id']), 'wrong exercise id' + if exercise_id != str(exercise['id']): + raise ValueError('wrong exercise id') for answer in posted_answers.values(): answers[exercise_id] = answer submission.answers = json.dumps(answers)