HTML generation in Celery.
[wolnelektury.git] / apps / suggest / forms.py
index a81579b..b98e0ae 100644 (file)
@@ -4,9 +4,10 @@
 #
 from django import forms
 from django.contrib.sites.models import Site
+from django.core.exceptions import ValidationError
 from django.core.mail import send_mail, mail_managers
 from django.core.urlresolvers import reverse
-from django.core.validators import email_re
+from django.core.validators import validate_email
 from django.utils.translation import ugettext_lazy as _
 from django.utils.translation import ugettext
 from suggest.models import PublishingSuggestion, Suggestion
@@ -41,15 +42,20 @@ Kontakt: %(contact)s
             'description': description,
             }, fail_silently=True)
 
-        if email_re.match(contact):
-            send_mail(u'[WolneLektury] ' + _(u'Thank you for your suggestion.'),
-                    _(u"""\
+        try:
+            validate_email(contact)
+        except ValidationError:
+            pass
+        else:
+            send_mail(u'[WolneLektury] ' +
+                    ugettext(u'Thank you for your suggestion.'),
+                    ugettext(u"""\
 Thank you for your comment on WolneLektury.pl.
 The suggestion has been referred to the project coordinator.""") +
 u"""
 
 -- 
-""" + _(u'''Message sent automatically. Please do not reply.'''),
+""" + ugettext(u'''Message sent automatically. Please do not reply.'''),
                     'no-reply@wolnelektury.pl', [contact], fail_silently=True)
 
 
@@ -60,7 +66,7 @@ class PublishingSuggestForm(forms.Form):
 
     def clean(self, *args, **kwargs):
         if not self.cleaned_data['books'] and not self.cleaned_data['audiobooks']:
-            msg = _(u"One of these fields is required.")
+            msg = ugettext(u"One of these fields is required.")
             self._errors["books"] = self.error_class([msg])
             self._errors["audiobooks"] = self.error_class([msg])
         return super(PublishingSuggestForm, self).clean(*args, **kwargs)
@@ -95,7 +101,11 @@ Audiobooki:
             'audiobooks': audiobooks,
             }, fail_silently=True)
 
-        if email_re.match(contact):
+        try:
+            validate_email(contact)
+        except ValidationError:
+            pass
+        else:
             send_mail(u'[WolneLektury] ' +
                     ugettext(u'Thank you for your suggestion.'),
                     ugettext(u"""\