lesmianator fix
[wolnelektury.git] / apps / suggest / views.py
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.
4 #
5 from django.http import HttpResponse, HttpResponseRedirect
6 from django.views.decorators import cache
7 from django.views.decorators.http import require_POST
8 from django.utils.translation import ugettext as _
9
10 from suggest import forms
11 from suggest.models import Suggestion
12
13 # FIXME - shouldn't be in catalogue
14 from catalogue.views import LazyEncoder
15
16
17 #@require_POST
18 @cache.never_cache
19 def report(request):
20     suggest_form = forms.SuggestForm(request.POST)
21     if suggest_form.is_valid():
22         contact = suggest_form.cleaned_data['contact']
23         description = suggest_form.cleaned_data['description']
24
25         suggestion = Suggestion(contact=contact,
26             description=description, ip=request.META['REMOTE_ADDR'])
27         if request.user.is_authenticated():
28             suggestion.user = request.user
29         suggestion.save()
30
31         response_data = {'success': True, 'message': _('Report was sent successfully.')}
32     else:
33         response_data = {'success': False, 'errors': suggest_form.errors}
34     return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))