1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django import forms
6 from django.core.mail import send_mail, mail_managers
7 from django.core.urlresolvers import reverse
8 from django.core.validators import email_re
9 from django.utils.translation import ugettext_lazy as _
10 from django.utils.translation import ugettext
13 from suggest.models import PublishingSuggestion
16 class SuggestForm(forms.Form):
17 contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
18 description = forms.CharField(label=_('Description'), widget=forms.Textarea, required=True)
21 class PublishingSuggestForm(forms.Form):
22 contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
23 books = forms.CharField(label=_('books'), widget=forms.Textarea, required=False)
24 audiobooks = forms.CharField(label=_('audiobooks'), widget=forms.Textarea, required=False)
26 def clean(self, *args, **kwargs):
27 if not self.cleaned_data['books'] and not self.cleaned_data['audiobooks']:
28 msg = _(u"One of these fields is required.")
29 self._errors["books"] = self.error_class([msg])
30 self._errors["audiobooks"] = self.error_class([msg])
31 return super(PublishingSuggestForm, self).clean(*args, **kwargs)
33 def save(self, request):
34 contact = self.cleaned_data['contact']
35 books = self.cleaned_data['books']
36 audiobooks = self.cleaned_data['audiobooks']
38 suggestion = PublishingSuggestion(contact=contact, books=books,
39 audiobooks=audiobooks, ip=request.META['REMOTE_ADDR'])
40 if request.user.is_authenticated():
41 suggestion.user = request.user
44 mail_managers(u'Konsultacja planu wydawniczego na WolneLektury.pl', u'''\
45 Zgłoszono nową sugestię nt. planu wydawniczego w serwisie WolneLektury.pl.
56 'url': request.build_absolute_uri(reverse('admin:suggest_suggestion_change', args=[suggestion.id])),
57 'user': str(request.user) if request.user.is_authenticated() else '',
60 'audiobooks': audiobooks,
61 }, fail_silently=True)
63 if email_re.match(contact):
64 send_mail(u'[WolneLektury] ' +
65 ugettext(u'Thank you for your suggestion.'),
67 Thank you for your comment on WolneLektury.pl.
68 The suggestion has been referred to the project coordinator.""") +
72 """ + ugettext(u'''Message sent automatically. Please do not reply.'''),
73 'no-reply@wolnelektury.pl', [contact], fail_silently=True)