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 contact = suggest_form.cleaned_data['contact']
23 description = suggest_form.cleaned_data['description']
25 suggestion = Suggestion(contact=contact,
26 description=description, ip=request.META['REMOTE_ADDR'])
27 if request.user.is_authenticated():
28 suggestion.user = request.user
31 response_data = {'success': True, 'message': _('Report was sent successfully.')}
33 response_data = {'success': False, 'errors': suggest_form.errors}
34 print LazyEncoder(ensure_ascii=False).encode(response_data)
35 return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))