X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/237dc400a6995da6d8a439d4abb173eecbe74a01..7fa5002e3aa435859aea7fb4e0c814b4034b6aa5:/apps/suggest/forms.py?ds=inline diff --git a/apps/suggest/forms.py b/apps/suggest/forms.py index 76170e1c6..b98e0ae4a 100644 --- a/apps/suggest/forms.py +++ b/apps/suggest/forms.py @@ -3,18 +3,61 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # 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 suggest.models import PublishingSuggestion +from django.utils.translation import ugettext +from suggest.models import PublishingSuggestion, Suggestion class SuggestForm(forms.Form): contact = forms.CharField(label=_('Contact'), max_length=120, required=False) description = forms.CharField(label=_('Description'), widget=forms.Textarea, required=True) + def save(self, request): + contact = self.cleaned_data['contact'] + description = self.cleaned_data['description'] + + suggestion = Suggestion(contact=contact, + description=description, ip=request.META['REMOTE_ADDR']) + if request.user.is_authenticated(): + suggestion.user = request.user + suggestion.save() + + mail_managers(u'Nowa sugestia na stronie WolneLektury.pl', u'''\ +Zgłoszono nową sugestię w serwisie WolneLektury.pl. +http://%(site)s%(url)s + +Użytkownik: %(user)s +Kontakt: %(contact)s + +%(description)s''' % { + 'site': Site.objects.get_current().domain, + 'url': reverse('admin:suggest_suggestion_change', args=[suggestion.id]), + 'user': str(request.user) if request.user.is_authenticated() else '', + 'contact': contact, + 'description': description, + }, fail_silently=True) + + 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""" + +-- +""" + ugettext(u'''Message sent automatically. Please do not reply.'''), + 'no-reply@wolnelektury.pl', [contact], fail_silently=True) + class PublishingSuggestForm(forms.Form): contact = forms.CharField(label=_('Contact'), max_length=120, required=False) @@ -23,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) @@ -58,13 +101,18 @@ Audiobooki: 'audiobooks': audiobooks, }, 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)