packaging zip deflated,
[wolnelektury.git] / apps / suggest / forms.py
index 5c034e6..14cec03 100644 (file)
@@ -7,6 +7,8 @@ from django.core.mail import send_mail, mail_managers
 from django.core.urlresolvers import reverse
 from django.core.validators import email_re
 from django.utils.translation import ugettext_lazy as _
 from django.core.urlresolvers import reverse
 from django.core.validators import email_re
 from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext
+
 
 from suggest.models import PublishingSuggestion
 
 
 from suggest.models import PublishingSuggestion
 
@@ -18,8 +20,15 @@ class SuggestForm(forms.Form):
 
 class PublishingSuggestForm(forms.Form):
     contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
 
 class PublishingSuggestForm(forms.Form):
     contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
-    books = forms.CharField(label=_('books'), widget=forms.Textarea, required=True)
-    audiobooks = forms.CharField(label=_('audiobooks'), widget=forms.Textarea, required=True)
+    books = forms.CharField(label=_('books'), widget=forms.Textarea, required=False)
+    audiobooks = forms.CharField(label=_('audiobooks'), widget=forms.Textarea, required=False)
+
+    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.")
+            self._errors["books"] = self.error_class([msg])
+            self._errors["audiobooks"] = self.error_class([msg])
+        return super(PublishingSuggestForm, self).clean(*args, **kwargs)
 
     def save(self, request):
         contact = self.cleaned_data['contact']
 
     def save(self, request):
         contact = self.cleaned_data['contact']
@@ -52,12 +61,13 @@ Audiobooki:
             }, fail_silently=True)
 
         if email_re.match(contact):
             }, fail_silently=True)
 
         if email_re.match(contact):
-            send_mail(u'[WolneLektury] ' + _(u'Thank you for your suggestion.'),
-                    _(u"""\
+            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"""
 
 -- 
 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)
                     'no-reply@wolnelektury.pl', [contact], fail_silently=True)