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 _
11 from suggest.models import PublishingSuggestion
14 class SuggestForm(forms.Form):
15 contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
16 description = forms.CharField(label=_('Description'), widget=forms.Textarea, required=True)
19 class PublishingSuggestForm(forms.Form):
20 contact = forms.CharField(label=_('Contact'), max_length=120, required=False)
21 books = forms.CharField(label=_('books'), widget=forms.Textarea, required=True)
22 audiobooks = forms.CharField(label=_('audiobooks'), widget=forms.Textarea, required=True)
24 def save(self, request):
25 contact = self.cleaned_data['contact']
26 books = self.cleaned_data['books']
27 audiobooks = self.cleaned_data['audiobooks']
29 suggestion = PublishingSuggestion(contact=contact, books=books,
30 audiobooks=audiobooks, ip=request.META['REMOTE_ADDR'])
31 if request.user.is_authenticated():
32 suggestion.user = request.user
35 mail_managers(u'Konsultacja planu wydawniczego na WolneLektury.pl', u'''\
36 Zgłoszono nową sugestię nt. planu wydawniczego w serwisie WolneLektury.pl.
47 'url': request.build_absolute_uri(reverse('admin:suggest_suggestion_change', args=[suggestion.id])),
48 'user': str(request.user) if request.user.is_authenticated() else '',
51 'audiobooks': audiobooks,
52 }, fail_silently=True)
54 if email_re.match(contact):
55 send_mail(u'[WolneLektury] ' + _(u'Thank you for your suggestion.'),
57 Thank you for your comment on WolneLektury.pl.
58 The suggestion has been referred to the project coordinator.""") +
62 """ + _(u'''Message sent automatically. Please do not reply.'''),
63 'no-reply@wolnelektury.pl', [contact], fail_silently=True)