set competition state in db + randomized single-question forms
[edumed.git] / edumed / contact_forms.py
index 8629dce..dd6cef8 100644 (file)
@@ -272,6 +272,8 @@ class OlimpiadaForm(ContactForm):
               u'oświadczam, że zostałam/em poinformowana/y o tym, że mam prawo wglądu w treść swoich danych '
               u'i możliwość ich poprawiania oraz że ich podanie jest dobrowolne, ale niezbędne do dokonania '
               u'zgłoszenia.')
+    zgoda_newsletter = forms.BooleanField(
+        label=u'Chcę otrzymywać newsletter: Edukacja medialna', required=False)
 
     extract_types = (dict(slug='extended', label=_('extended')),)
 
@@ -312,14 +314,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