##// END OF EJS Templates
make FilesRedirectHandler redirect logic accessible...
Min RK -
Show More
@@ -464,7 +464,13 b' class TrailingSlashHandler(web.RequestHandler):'
464
464
465 class FilesRedirectHandler(IPythonHandler):
465 class FilesRedirectHandler(IPythonHandler):
466 """Handler for redirecting relative URLs to the /files/ handler"""
466 """Handler for redirecting relative URLs to the /files/ handler"""
467 def get(self, path=''):
467
468 @staticmethod
469 def redirect_to_files(self, path):
470 """make redirect logic a reusable static method
471
472 so it can be called from other handlers.
473 """
468 cm = self.contents_manager
474 cm = self.contents_manager
469 if cm.dir_exists(path):
475 if cm.dir_exists(path):
470 # it's a *directory*, redirect to /tree
476 # it's a *directory*, redirect to /tree
@@ -488,6 +494,9 b' class FilesRedirectHandler(IPythonHandler):'
488 url = url_escape(url)
494 url = url_escape(url)
489 self.log.debug("Redirecting %s to %s", self.request.path, url)
495 self.log.debug("Redirecting %s to %s", self.request.path, url)
490 self.redirect(url)
496 self.redirect(url)
497
498 def get(self, path=''):
499 return self.redirect_to_files(self, path)
491
500
492
501
493 #-----------------------------------------------------------------------------
502 #-----------------------------------------------------------------------------
@@ -28,12 +28,12 b' class NotebookHandler(IPythonHandler):'
28 except web.HTTPError as e:
28 except web.HTTPError as e:
29 if e.status_code == 404 and 'files' in path.split('/'):
29 if e.status_code == 404 and 'files' in path.split('/'):
30 # 404, but '/files/' in URL, let FilesRedirect take care of it
30 # 404, but '/files/' in URL, let FilesRedirect take care of it
31 return FilesRedirectHandler.get(self, path)
31 return FilesRedirectHandler.redirect_to_files(self, path)
32 else:
32 else:
33 raise
33 raise
34 if model['type'] != 'notebook':
34 if model['type'] != 'notebook':
35 # not a notebook, redirect to files
35 # not a notebook, redirect to files
36 return FilesRedirectHandler.get(self, path)
36 return FilesRedirectHandler.redirect_to_files(self, path)
37 name = url_escape(path.rsplit('/', 1)[-1])
37 name = url_escape(path.rsplit('/', 1)[-1])
38 path = url_escape(path)
38 path = url_escape(path)
39 self.write(self.render_template('notebook.html',
39 self.write(self.render_template('notebook.html',
General Comments 0
You need to be logged in to leave comments. Login now