+class AjaxableFormView(object):
+ formClass = None
+ template = None
+ ajax_template = None
+ formname = None
+
+ def __call__(self, request):
+ """
+ A view displaying a form, or JSON if `ajax' GET param is set.
+ """
+ ajax = request.GET.get('ajax', False)
+ if request.method == "POST":
+ form = self.formClass(request.POST)
+ if form.is_valid():
+ form.save(request)
+ response_data = {'success': True, 'message': _('Report was sent successfully.')}
+ else:
+ response_data = {'success': False, 'errors': form.errors}
+ if ajax:
+ return HttpResponse(LazyEncoder(ensure_ascii=False).encode(response_data))
+ else:
+ form = self.formClass()
+ response_data = None
+
+ template = self.ajax_template if ajax else self.template
+ return render_to_response(template, {
+ self.formname: form,
+ "form": SearchForm(),
+ "response_data": response_data,
+ },
+ context_instance=RequestContext(request))
+
+
+class PublishingSuggestionFormView(AjaxableFormView):
+ formClass = forms.PublishingSuggestForm
+ ajax_template = "publishing_suggest.html"
+ template = "publishing_suggest_full.html"
+ formname = "pubsuggest_form"
+
+
+@require_POST