Fix AJAX form posting that work incorrectly if get() in base views

is overridden by subclass, e.g. EditRulesView and EditAttachmentsView
if they don't add X-Horizon-Location custom headers if redirect is
used. This mucking is probably the cleanest way to fix this in
the meantime.

 * fix bug 961863

Change-Id: I213e23a150b4afaba1249584e8cb3b376095533e
This commit is contained in:
Andy Chong
2012-03-22 13:34:40 +08:00
parent 479ebdc3ff
commit 05b208f104

View File

@@ -80,3 +80,15 @@ class HorizonMiddleware(object):
if exception.message:
messages.error(request, exception.message)
return shortcuts.redirect(exception.location)
def process_response(self, request, response):
"""
Convert HttpResponseRedirect to HttpResponse if request is via ajax
to allow ajax request to redirect url
"""
if request.is_ajax():
if type(response) == http.HttpResponseRedirect:
redirect_response = http.HttpResponse()
redirect_response['X-Horizon-Location'] = response['location']
return redirect_response
return response