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.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 _
10 from suggest import forms
11 from suggest.models import Suggestion
13 # FIXME - shouldn't be in catalogue
14 from catalogue.views import LazyEncoder
20 suggest_form = forms.SuggestForm(request.POST)
21 if suggest_form.is_valid():
22 author = suggest_form.cleaned_data['author']
23 email = suggest_form.cleaned_data['email']
24 title = suggest_form.cleaned_data['title']
25 description = suggest_form.cleaned_data['description']
27 suggestion = Suggestion(author=author, email=email, title=title,
28 description=description, ip=request.META['REMOTE_ADDR'])
29 if request.user.is_authenticated():
30 suggestion.user = request.user
33 response_data = {'success': True, 'message': _('Report was sent successfully.')}
35 response_data = {'success': False, 'errors': suggest_form.errors}
36 print LazyEncoder(ensure_ascii=False).encode(response_data)
37 return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))