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.core.mail import send_mail, mail_managers
6 from django.core.urlresolvers import reverse
7 from django.core.validators import email_re
8 from django.http import HttpResponse, HttpResponseRedirect
9 from django.utils.translation import ugettext as _
10 from django.views.decorators import cache
11 from django.views.decorators.http import require_POST
13 from suggest import forms
14 from suggest.models import Suggestion
16 # FIXME - shouldn't be in catalogue
17 from catalogue.views import LazyEncoder
23 suggest_form = forms.SuggestForm(request.POST)
24 if suggest_form.is_valid():
25 contact = suggest_form.cleaned_data['contact']
26 description = suggest_form.cleaned_data['description']
28 suggestion = Suggestion(contact=contact,
29 description=description, ip=request.META['REMOTE_ADDR'])
30 if request.user.is_authenticated():
31 suggestion.user = request.user
34 mail_managers(u'Nowa sugestia na stronie WolneLektury.pl', u'''\
35 Zgłoszono nową sugestię w serwisie WolneLektury.pl.
41 %(description)s''' % {
42 'url': reverse('admin:suggest_suggestion_change', args=[suggestion.id]),
43 'user': str(request.user),
45 'description': description,
46 }, fail_silently=True)
48 if email_re.match(contact):
49 send_mail(u'[WolneLektury] ' + _(u'Thank you for your suggestion.'),
51 Thank you for your comment on WolneLektury.pl.
52 The suggestion has been referred to the project coordinator.""") +
56 """ + _(u'''Message sent automatically. Please do not reply.'''),
57 'no-reply@wolnelektury.pl', [contact], fail_silently=True)
59 response_data = {'success': True, 'message': _('Report was sent successfully.')}
61 response_data = {'success': False, 'errors': suggest_form.errors}
62 return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))