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
12 from django.contrib.sites.models import Site
14 from suggest import forms
15 from suggest.models import Suggestion
17 # FIXME - shouldn't be in catalogue
18 from catalogue.views import LazyEncoder
24 suggest_form = forms.SuggestForm(request.POST)
25 if suggest_form.is_valid():
26 contact = suggest_form.cleaned_data['contact']
27 description = suggest_form.cleaned_data['description']
29 suggestion = Suggestion(contact=contact,
30 description=description, ip=request.META['REMOTE_ADDR'])
31 if request.user.is_authenticated():
32 suggestion.user = request.user
35 mail_managers(u'Nowa sugestia na stronie WolneLektury.pl', u'''\
36 Zgłoszono nową sugestię w serwisie WolneLektury.pl.
37 http://%(site)s%(url)s
42 %(description)s''' % {
43 'site': Site.objects.get_current().domain,
44 'url': reverse('admin:suggest_suggestion_change', args=[suggestion.id]),
45 'user': str(request.user) if request.user.is_authenticated() else '',
47 'description': description,
48 }, fail_silently=True)
50 if email_re.match(contact):
51 send_mail(u'[WolneLektury] ' + _(u'Thank you for your suggestion.'),
53 Thank you for your comment on WolneLektury.pl.
54 The suggestion has been referred to the project coordinator.""") +
58 """ + _(u'''Message sent automatically. Please do not reply.'''),
59 'no-reply@wolnelektury.pl', [contact], fail_silently=True)
61 response_data = {'success': True, 'message': _('Report was sent successfully.')}
63 response_data = {'success': False, 'errors': suggest_form.errors}
64 return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))