X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/7292df047d1c9c630f66fdc75c5f5d0c50fd9800..f80843488568354f61435d0ffd31ec387cb8f0ac:/wtem/views.py?ds=inline diff --git a/wtem/views.py b/wtem/views.py index 7726167..0696174 100644 --- a/wtem/views.py +++ b/wtem/views.py @@ -49,13 +49,16 @@ def form_during(request, key): else: return render(request, 'wtem/key_not_found.html') exercises_with_answers = deepcopy(exercises) - answers = json.loads(submission.answers) + if submission.answers: + answers = json.loads(submission.answers) + else: + answers = {} for exercise in exercises_with_answers: - exercise['saved_answer'] = answers[str(exercise['id'])] + exercise['saved_answer'] = answers.get(str(exercise['id']), '') if exercise['type'] == 'open' and exercise.get('fields'): field_answers = {field['id']: field['text'] for field in exercise['saved_answer']} for field in exercise['fields']: - field['saved_answer'] = field_answers.get(field['id']) + field['saved_answer'] = field_answers.get(field['id'], '') if request.method == 'GET': return render(request, 'wtem/main.html', {'exercises': exercises_with_answers, 'end_time': submission.end_time}) elif request.method == 'POST':