Cite backdrop z książkami
[wolnelektury.git] / apps / suggest / views.py
index cd733a8..15b65f2 100644 (file)
@@ -2,36 +2,22 @@
 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
-from django.http import HttpResponse, HttpResponseRedirect
-from django.views.decorators import cache
-from django.views.decorators.http import require_POST
-from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext_lazy as _
 
 
+from ajaxable.utils import AjaxableFormView
 from suggest import forms
 from suggest import forms
-from suggest.models import Suggestion
+from suggest.models import Suggestion, PublishingSuggestion
 
 
-# FIXME - shouldn't be in catalogue
-from catalogue.views import LazyEncoder 
 
 
+class PublishingSuggestionFormView(AjaxableFormView):
+    form_class = forms.PublishingSuggestForm
+    title = _('Report a bug or suggestion')
+    template = "publishing_suggest.html"
+    success_message = _('Report was sent successfully.')
 
 
-#@require_POST
-@cache.never_cache
-def report(request):
-    suggest_form = forms.SuggestForm(request.POST)
-    if suggest_form.is_valid():
-        author = suggest_form.cleaned_data['author']
-        email = suggest_form.cleaned_data['email']
-        title = suggest_form.cleaned_data['title']
-        description = suggest_form.cleaned_data['description']
 
 
-        suggestion = Suggestion(author=author, email=email, title=title,
-            description=description, ip=request.META['REMOTE_ADDR'])
-        if request.user.is_authenticated():
-            suggestion.user = request.user
-        suggestion.save()
-
-        response_data = {'success': True, 'message': _('Report was sent successfully.')}
-    else:
-        response_data = {'success': False, 'errors': suggest_form.errors}
-    print LazyEncoder(ensure_ascii=False).encode(response_data)
-    return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))
+class SuggestionFormView(AjaxableFormView):
+    form_class = forms.SuggestForm
+    title = _('Report a bug or suggestion')
+    submit = _('Send report')
+    success_message = _('Report was sent successfully.')