From: Jan Szejko Date: Wed, 9 Nov 2016 14:47:22 +0000 (+0100) Subject: fix for when there are no students X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/836e87743276449d019848fb53b520b4c4851908?ds=inline;hp=6edf5be82b9e97e3d03f88f50a32b9815ac9688d fix for when there are no students --- diff --git a/edumed/contact_forms.py b/edumed/contact_forms.py index 3c222de..7e7faca 100644 --- a/edumed/contact_forms.py +++ b/edumed/contact_forms.py @@ -276,7 +276,8 @@ class OlimpiadaForm(ContactForm): @staticmethod def get_extract_fields(contact, extract_type_slug): fields = contact.body.keys() - fields.remove('student') + if 'student' in fields: + fields.remove('student') fields.extend(['contact', 'student_first_name', 'student_last_name', 'student_email']) return fields @@ -293,12 +294,13 @@ class OlimpiadaForm(ContactForm): toret[0][field_name] = val current = toret[0] - for student in contact.body['student']: - for attr in ('first_name', 'last_name', 'email'): - current['student_' + attr] = student[attr] - if current not in toret: - toret.append(current) - current = {} + if 'student' in contact.body: + for student in contact.body['student']: + for attr in ('first_name', 'last_name', 'email'): + current['student_' + attr] = student[attr] + if current not in toret: + toret.append(current) + current = {} return toret def save(self, request, formsets=None):