fix contact admin?
[edumed.git] / edumed / contact_forms.py
index 2cb7dd9..8358907 100644 (file)
@@ -308,28 +308,20 @@ class OlimpiadaForm(ContactForm):
     def save(self, request, formsets=None):
         contact = super(OlimpiadaForm, self).save(request, formsets)
 
     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)
         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
 
 
         return contact