diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index 025a8c3..11d8bde 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -222,7 +222,7 @@ class IPythonHandler(AuthenticatedHandler): return self.settings['session_manager'] @property - def project(self): + def project_dir(self): return self.notebook_manager.notebook_dir #--------------------------------------------------------------- diff --git a/IPython/html/templates/tree.html b/IPython/html/templates/tree.html index a794933..a870436 100644 --- a/IPython/html/templates/tree.html +++ b/IPython/html/templates/tree.html @@ -13,7 +13,6 @@ data-project={{project}} data-base-project-url={{base_project_url}} data-notebook-path={{notebook_path}} -data-notebook-name={{notebook_name}} data-base-kernel-url={{base_kernel_url}} {% endblock %} @@ -48,7 +47,7 @@ data-base-kernel-url={{base_kernel_url}}
diff --git a/IPython/html/tree/handlers.py b/IPython/html/tree/handlers.py index d0451bb..b7d7614 100644 --- a/IPython/html/tree/handlers.py +++ b/IPython/html/tree/handlers.py @@ -15,64 +15,49 @@ Authors: #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- +import os from tornado import web from ..base.handlers import IPythonHandler +from ..utils import url_path_join, path2url, url2path #----------------------------------------------------------------------------- # Handlers #----------------------------------------------------------------------------- -class ProjectDashboardHandler(IPythonHandler): +class TreeHandler(IPythonHandler): + """Render the tree view, listing notebooks, clusters, etc.""" @web.authenticated - def get(self): - self.write(self.render_template('tree.html', - project=self.project, - project_component=self.project.split('/'), - notebook_path= "/" - )) - - -class ProjectPathDashboardHandler(IPythonHandler): - - @web.authenticated - def get(self, notebook_path): + def get(self, notebook_path=""): nbm = self.notebook_manager name, path = nbm.named_notebook_path(notebook_path) if name is not None: - # ends with .ipynb - self.redirect(self.base_project_url + 'notebooks' + path + name) + # is a notebook, redirect to notebook handler + url = url_path_join(self.base_project_url, 'notebooks', path, name) + self.redirect(url) else: - project = self.project + path - path = nbm.url_encode(path) + location = nbm.get_os_path(path=path) + + if not os.path.exists(location): + # no such directory, 404 + raise web.HTTPError(404) + self.write(self.render_template('tree.html', - project=project, - project_component=project.split('/')[:-1], + project=self.project_dir, + tree_url_path=path2url(location), notebook_path=path, - notebook_name=name)) + )) class TreeRedirectHandler(IPythonHandler): - - @web.authenticated - def get(self): - url = self.base_project_url + 'tree' - self.redirect(url) - -class TreePathRedirectHandler(IPythonHandler): - - @web.authenticated - def get(self, notebook_path): - url = self.base_project_url + 'tree/'+ notebook_path+'/' - self.redirect(url) + """Redirect a request to the corresponding tree URL""" -class ProjectRedirectHandler(IPythonHandler): - @web.authenticated - def get(self): - url = self.base_project_url + 'tree' + def get(self, notebook_path=''): + url = url_path_join(self.base_project_url, 'tree', notebook_path) + self.log.debug("Redirecting %s to %s", self.request.uri, url) self.redirect(url) @@ -84,9 +69,9 @@ class ProjectRedirectHandler(IPythonHandler): _notebook_path_regex = r"(?P.+)" default_handlers = [ - (r"/tree/%s/" % _notebook_path_regex, ProjectPathDashboardHandler), - (r"/tree/%s" % _notebook_path_regex, TreePathRedirectHandler), - (r"/tree", ProjectDashboardHandler), + (r"/tree/%s/" % _notebook_path_regex, TreeRedirectHandler), + (r"/tree/%s" % _notebook_path_regex, TreeHandler), (r"/tree/", TreeRedirectHandler), - (r"/", ProjectRedirectHandler) + (r"/tree", TreeHandler), + (r"/", TreeRedirectHandler), ]