redirect(...) now works on ajax responses, thanks Anthony
This commit is contained in:
+9
-4
@@ -119,13 +119,18 @@ class HTTP(BaseException):
|
||||
return self.message
|
||||
|
||||
|
||||
def redirect(location, how=303):
|
||||
def redirect(location, how=303, type=None):
|
||||
from gluon import current
|
||||
type = type or ('client' if current.request.ajax else 'http')
|
||||
if not location:
|
||||
return
|
||||
location = location.replace('\r', '%0D').replace('\n', '%0A')
|
||||
raise HTTP(how,
|
||||
'You are being redirected <a href="%s">here</a>' % location,
|
||||
Location=location)
|
||||
if type == 'client':
|
||||
raise HTTP(200, **{'web2py-redirect-location': location})
|
||||
else:
|
||||
raise HTTP(how,
|
||||
'You are being redirected <a href="%s">here</a>' % location,
|
||||
Location=location)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user