##// END OF EJS Templates
use contents manager to handle redirect of /notebooks -> /files...
MinRK -
Show More
@@ -60,20 +60,23 b' class NotebookRedirectHandler(IPythonHandler):'
60 # it's a *directory*, redirect to /tree
60 # it's a *directory*, redirect to /tree
61 url = url_path_join(self.base_url, 'tree', path)
61 url = url_path_join(self.base_url, 'tree', path)
62 else:
62 else:
63 orig_path = path
63 # otherwise, redirect to /files
64 # otherwise, redirect to /files
64 if '/files/' in path:
65 parts = path.split('/')
66 path = '/'.join(parts[:-1])
67 name = parts[-1]
68
69 if not cm.file_exists(name=name, path=path) and 'files' in parts:
65 # redirect without files/ iff it would 404
70 # redirect without files/ iff it would 404
66 # this preserves pre-2.0-style 'files/' links
71 # this preserves pre-2.0-style 'files/' links
67 # FIXME: this is hardcoded based on notebook_path,
72 self.log.warn("Deprecated files/ URL: %s", orig_path)
68 # but so is the files handler itself,
73 parts.remove('files')
69 # so it should work until both are cleaned up.
74 path = '/'.join(parts[:-1])
70 parts = path.split('/')
75
71 files_path = os.path.join(cm.root_dir, *parts)
76 if not cm.file_exists(name=name, path=path):
72 if not os.path.exists(files_path):
77 raise web.HTTPError(404)
73 self.log.warn("Deprecated files/ URL: %s", path)
74 path = path.replace('/files/', '/', 1)
75
78
76 url = url_path_join(self.base_url, 'files', path)
79 url = url_path_join(self.base_url, 'files', path, name)
77 url = url_escape(url)
80 url = url_escape(url)
78 self.log.debug("Redirecting %s to %s", self.request.path, url)
81 self.log.debug("Redirecting %s to %s", self.request.path, url)
79 self.redirect(url)
82 self.redirect(url)
General Comments 0
You need to be logged in to leave comments. Login now