make FilesRedirectHandler redirect logic accessible

from a static method

instead of calling FRH.get(self), which doesn't work on Python 2
due to unbound method class checking.
Min RK 11 years ago
parent 86dca85890
commit c6b610f04f

@ -464,7 +464,13 @@ class TrailingSlashHandler(web.RequestHandler):
class FilesRedirectHandler(IPythonHandler):
"""Handler for redirecting relative URLs to the /files/ handler"""
def get(self, path=''):
@staticmethod
def redirect_to_files(self, path):
"""make redirect logic a reusable static method
so it can be called from other handlers.
"""
cm = self.contents_manager
if cm.dir_exists(path):
# it's a *directory*, redirect to /tree
@ -488,6 +494,9 @@ class FilesRedirectHandler(IPythonHandler):
url = url_escape(url)
self.log.debug("Redirecting %s to %s", self.request.path, url)
self.redirect(url)
def get(self, path=''):
return self.redirect_to_files(self, path)
#-----------------------------------------------------------------------------

@ -28,12 +28,12 @@ class NotebookHandler(IPythonHandler):
except web.HTTPError as e:
if e.status_code == 404 and 'files' in path.split('/'):
# 404, but '/files/' in URL, let FilesRedirect take care of it
return FilesRedirectHandler.get(self, path)
return FilesRedirectHandler.redirect_to_files(self, path)
else:
raise
if model['type'] != 'notebook':
# not a notebook, redirect to files
return FilesRedirectHandler.get(self, path)
return FilesRedirectHandler.redirect_to_files(self, path)
name = url_escape(path.rsplit('/', 1)[-1])
path = url_escape(path)
self.write(self.render_template('notebook.html',

Loading…
Cancel
Save