From 7adb123aef4539364d30452099423ec54a60ae01 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Wed, 27 Sep 2017 11:31:59 +0200 Subject: [PATCH] don't try to confirm empty students --- edumed/contact_forms.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/edumed/contact_forms.py b/edumed/contact_forms.py index 8629dce..8358907 100644 --- a/edumed/contact_forms.py +++ b/edumed/contact_forms.py @@ -312,14 +312,16 @@ class OlimpiadaForm(ContactForm): if formset.prefix == 'student': for f in formset.forms: email = f.cleaned_data.get('email', None) - try: - Confirmation.objects.get(email=email) - except Confirmation.DoesNotExist: - first_name = f.cleaned_data.get('first_name', None) - last_name = f.cleaned_data.get('last_name', None) - confirmation = Confirmation.create( - first_name=first_name, last_name=last_name, email=email, contact=contact) - confirmation.send_mail() + if email: + try: + Confirmation.objects.get(email=email) + except Confirmation.DoesNotExist: + first_name = f.cleaned_data.get('first_name', None) + last_name = f.cleaned_data.get('last_name', None) + if first_name and last_name: + confirmation = Confirmation.create( + first_name=first_name, last_name=last_name, email=email, contact=contact) + confirmation.send_mail() return contact -- 2.20.1