From 1b1d1f23256d56e6de2b18cd66064b2fa83f3e82 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Wed, 19 Nov 2014 11:52:03 +0100 Subject: [PATCH] fix clientside notebook manager and assume tree is dir by default Assume tree url are dir by default instead of file, and if not do a redirect. Usefull for Clientside manager where the server does not know the content of the drive, and think that everythong exists. --- IPython/html/tree/handlers.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/IPython/html/tree/handlers.py b/IPython/html/tree/handlers.py index 9bd3d95bd..cf94e5c6c 100644 --- a/IPython/html/tree/handlers.py +++ b/IPython/html/tree/handlers.py @@ -36,21 +36,8 @@ class TreeHandler(IPythonHandler): def get(self, path=''): path = path.strip('/') cm = self.contents_manager - if cm.file_exists(path): - # it's not a directory, we have redirecting to do - model = cm.get(path, content=False) - # redirect to /api/notebooks if it's a notebook, otherwise /api/files - service = 'notebooks' if model['type'] == 'notebook' else 'files' - url = url_escape(url_path_join( - self.base_url, service, path, - )) - self.log.debug("Redirecting %s to %s", self.request.path, url) - self.redirect(url) - else: - if not cm.dir_exists(path=path): - # Directory is hidden or does not exist. - raise web.HTTPError(404) - elif cm.is_hidden(path): + if cm.dir_exists(path=path): + if cm.is_hidden(path): self.log.info("Refusing to serve hidden directory, via 404 Error") raise web.HTTPError(404) breadcrumbs = self.generate_breadcrumbs(path) @@ -61,6 +48,18 @@ class TreeHandler(IPythonHandler): breadcrumbs=breadcrumbs, terminals_available=self.settings['terminals_available'], )) + elif cm.file_exists(path): + # it's not a directory, we have redirecting to do + model = cm.get(path, content=False) + # redirect to /api/notebooks if it's a notebook, otherwise /api/files + service = 'notebooks' if model['type'] == 'notebook' else 'files' + url = url_escape(url_path_join( + self.base_url, service, path, + )) + self.log.debug("Redirecting %s to %s", self.request.path, url) + self.redirect(url) + else: + raise web.HTTPError(404) #-----------------------------------------------------------------------------