set competition state in db + randomized single-question forms
[edumed.git] / edumed / contact_forms.py
index 2cb7dd9..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')),)
 
@@ -308,28 +310,20 @@ class OlimpiadaForm(ContactForm):
     def save(self, request, formsets=None):
         contact = super(OlimpiadaForm, self).save(request, formsets)
 
-        mail_subject = render_to_string('contact/olimpiada/student_mail_subject.html').strip()
         for formset in formsets or []:
             if formset.prefix == 'student':
                 for f in formset.forms:
                     email = f.cleaned_data.get('email', None)
-                    try:
-                        confirmation = 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)
-                    mail_body = render_to_string(
-                        'contact/olimpiada/student_mail_body.html', {'confirmation': confirmation})
-                    try:
-                        validate_email(email)
-                    except ValidationError:
-                        pass
-                    else:
-                        send_mail(mail_subject, mail_body, 'olimpiada@nowoczesnapolska.org.pl', [email],
-                                  fail_silently=True)
-
+                    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