Commit 50ac15ee by Kálmán Viktor

Merge branch 'issue-435' into 'master'

Fix wrong content type for ajax requests

closes #435

See merge request !358
parents 7afa3d5b be51f177
...@@ -30,7 +30,9 @@ from django.core.urlresolvers import reverse ...@@ -30,7 +30,9 @@ from django.core.urlresolvers import reverse
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.views import redirect_to_login from django.contrib.auth.views import redirect_to_login
from django.db.models import Q 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.shortcuts import redirect, render
from django.utils.translation import ugettext_lazy as _, ugettext_noop from django.utils.translation import ugettext_lazy as _, ugettext_noop
from django.views.generic import DetailView, View, DeleteView from django.views.generic import DetailView, View, DeleteView
...@@ -343,12 +345,9 @@ class AjaxOperationMixin(object): ...@@ -343,12 +345,9 @@ class AjaxOperationMixin(object):
store.used = True store.used = True
else: else:
store = [] store = []
return HttpResponse( return JsonResponse({'success': True,
json.dumps({'success': True,
'with_reload': self.with_reload, 'with_reload': self.with_reload,
'messages': [unicode(m) for m in store]}), 'messages': [unicode(m) for m in store]})
content_type="application=json"
)
else: else:
return resp return resp
...@@ -378,11 +377,8 @@ class FormOperationMixin(object): ...@@ -378,11 +377,8 @@ class FormOperationMixin(object):
resp = super(FormOperationMixin, self).post( resp = super(FormOperationMixin, self).post(
request, extra, *args, **kwargs) request, extra, *args, **kwargs)
if request.is_ajax(): if request.is_ajax():
return HttpResponse( return JsonResponse({'success': True,
json.dumps({ 'with_reload': self.with_reload})
'success': True,
'with_reload': self.with_reload}),
content_type="application=json")
else: else:
return resp return resp
else: else:
......
...@@ -28,7 +28,9 @@ from django.contrib.auth.decorators import login_required ...@@ -28,7 +28,9 @@ from django.contrib.auth.decorators import login_required
from django.core import signing from django.core import signing
from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.core.urlresolvers import reverse, reverse_lazy 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.shortcuts import redirect, get_object_or_404
from django.template import RequestContext from django.template import RequestContext
from django.template.loader import render_to_string from django.template.loader import render_to_string
...@@ -274,10 +276,7 @@ class VmDetailView(GraphMixin, CheckedDetailView): ...@@ -274,10 +276,7 @@ class VmDetailView(GraphMixin, CheckedDetailView):
message = u"Not success" message = u"Not success"
if request.is_ajax(): if request.is_ajax():
return HttpResponse( return JsonResponse({'message': message})
json.dumps({'message': message}),
content_type="application=json"
)
else: else:
return redirect(reverse_lazy("dashboard.views.detail", return redirect(reverse_lazy("dashboard.views.detail",
kwargs={'pk': self.object.pk})) kwargs={'pk': self.object.pk}))
...@@ -563,11 +562,8 @@ class VmResourcesChangeView(VmOperationView): ...@@ -563,11 +562,8 @@ class VmResourcesChangeView(VmOperationView):
if request.is_ajax(): # this is not too nice if request.is_ajax(): # this is not too nice
store = messages.get_messages(request) store = messages.get_messages(request)
store.used = True store.used = True
return HttpResponse( return JsonResponse({'success': False,
json.dumps({'success': False, 'messages': [unicode(m) for m in store]})
'messages': [unicode(m) for m in store]}),
content_type="application=json"
)
else: else:
return HttpResponseRedirect(instance.get_absolute_url() + return HttpResponseRedirect(instance.get_absolute_url() +
"#resources") "#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