Commit be51f177 by Kálmán Viktor

dashboard: fix wrong content type for ajax requests

closes #435
parent dad93220
......@@ -30,7 +30,9 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.contrib.auth.views import redirect_to_login
from django.db.models import Q
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.http import (
HttpResponse, Http404, HttpResponseRedirect, JsonResponse
)
from django.shortcuts import redirect, render
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from django.views.generic import DetailView, View, DeleteView
......@@ -343,12 +345,9 @@ class AjaxOperationMixin(object):
store.used = True
else:
store = []
return HttpResponse(
json.dumps({'success': True,
return JsonResponse({'success': True,
'with_reload': self.with_reload,
'messages': [unicode(m) for m in store]}),
content_type="application=json"
)
'messages': [unicode(m) for m in store]})
else:
return resp
......@@ -378,11 +377,8 @@ class FormOperationMixin(object):
resp = super(FormOperationMixin, self).post(
request, extra, *args, **kwargs)
if request.is_ajax():
return HttpResponse(
json.dumps({
'success': True,
'with_reload': self.with_reload}),
content_type="application=json")
return JsonResponse({'success': True,
'with_reload': self.with_reload})
else:
return resp
else:
......
......@@ -28,7 +28,9 @@ from django.contrib.auth.decorators import login_required
from django.core import signing
from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.http import (
HttpResponse, Http404, HttpResponseRedirect, JsonResponse
)
from django.shortcuts import redirect, get_object_or_404
from django.template import RequestContext
from django.template.loader import render_to_string
......@@ -274,10 +276,7 @@ class VmDetailView(GraphMixin, CheckedDetailView):
message = u"Not success"
if request.is_ajax():
return HttpResponse(
json.dumps({'message': message}),
content_type="application=json"
)
return JsonResponse({'message': message})
else:
return redirect(reverse_lazy("dashboard.views.detail",
kwargs={'pk': self.object.pk}))
......@@ -563,11 +562,8 @@ class VmResourcesChangeView(VmOperationView):
if request.is_ajax(): # this is not too nice
store = messages.get_messages(request)
store.used = True
return HttpResponse(
json.dumps({'success': False,
'messages': [unicode(m) for m in store]}),
content_type="application=json"
)
return JsonResponse({'success': False,
'messages': [unicode(m) for m in store]})
else:
return HttpResponseRedirect(instance.get_absolute_url() +
"#resources")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment