Commit bc0eff84 by benjaoming Committed by Juan Diego Caballero

JSON view can return HttpResponseRedirect

parent 71a64575
......@@ -2,6 +2,7 @@
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseNotFound, \
HttpResponseForbidden
from django.http import HttpResponseRedirectBase
from django.shortcuts import redirect, get_object_or_404
from django.template.context import RequestContext
from django.template.loader import render_to_string
......@@ -15,6 +16,11 @@ from django.utils.http import urlquote
def json_view(func):
def wrap(request, *args, **kwargs):
obj = func(request, *args, **kwargs)
if isinstance(obj, HttpResponseRedirectBase):
# Special behaviour: If it's a redirect, for instance
# because of login protection etc. just return
# the redirect
return obj
data = json.dumps(obj, ensure_ascii=False)
status = kwargs.get('status', 200)
response = HttpResponse(mimetype='application/json', status=status)
......
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 to comment