From 8281b33e18266fd896db91e44be8b814a48a67dd Mon Sep 17 00:00:00 2001 From: Sigurd Gartmann Date: Sat, 30 Jun 2012 15:10:49 +0200 Subject: [PATCH] Allow for normal get and post delete, and ajax get delete. Needed for #12 and #14 --- fileupload/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fileupload/views.py b/fileupload/views.py index 4acb360..1747056 100644 --- a/fileupload/views.py +++ b/fileupload/views.py @@ -1,7 +1,7 @@ from fileupload.models import Picture from django.views.generic import CreateView, DeleteView -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.utils import simplejson from django.core.urlresolvers import reverse @@ -35,9 +35,12 @@ def delete(self, request, *args, **kwargs): """ self.object = self.get_object() self.object.delete() - response = JSONResponse(True, {}, response_mimetype(self.request)) - response['Content-Disposition'] = 'inline; filename=files.json' - return response + if request.is_ajax(): + response = JSONResponse(True, {}, response_mimetype(self.request)) + response['Content-Disposition'] = 'inline; filename=files.json' + return response + else: + return HttpResponseRedirect('/upload/new') class JSONResponse(HttpResponse): """JSON response class."""