cleanup CBV for document_upload
authorSeth Woodworth <seth@sethish.com>
Wed, 28 Aug 2013 17:45:07 +0000 (13:45 -0400)
committerSeth Woodworth <seth@sethish.com>
Wed, 28 Aug 2013 17:45:07 +0000 (13:45 -0400)
karmaworld/apps/document_upload/views.py

index 5b7fe2eb7c49a6900a94ea2eb940bccd5568d098..4352ed263f499d2f0165c4384865dee84e9db289 100644 (file)
@@ -21,38 +21,3 @@ def save_fp_upload(request):
         return HttpResponse({'success'})
     else:
         return HttpResponse(r_d_f.errors, status=400)
-
-
-
-class AjaxableResponseMixin(object):
-    """
-    Mixin to add AJAX support to a form.
-    Must be used with an object-based FormView (e.g. CreateView)
-    """
-    def render_to_json_response(self, context, **response_kwargs):
-        data = json.dumps(context)
-        response_kwargs['content_type'] = 'application/json'
-        return HttpResponse(data, **response_kwargs)
-
-    def form_invalid(self, form):
-        response = super(AjaxableResponseMixin, self).form_invalid(form)
-        if self.request.is_ajax():
-            return self.render_to_json_response(form.errors, status=400)
-        else:
-            return response
-
-    def form_valid(self, form):
-        # We make sure to call the parent's form_valid() method because
-        # it might do some processing (in the case of CreateView, it will
-        # call form.save() for example).
-        response = super(AjaxableResponseMixin, self).form_valid(form)
-        if self.request.is_ajax():
-            data = {
-                'pk': self.object.pk,
-            }
-            return self.render_to_json_response(data)
-        else:
-            return response
-
-class RawDocumentCreate(AjaxableResponseMixin, CreateView):
-    model = RawDocument