diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 9af122c..5b118a0 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -609,6 +609,20 @@ class ShellHandler(AuthenticatedZMQStreamHandler): # Notebook web service handlers #----------------------------------------------------------------------------- +class NotebookRedirectHandler(AuthenticatedHandler): + + @authenticate_unless_readonly + def get(self, notebook_name): + app = self.application + if notebook_name.endswith('.ipynb'): + notebook_name = notebook_name[:-6] + notebook_id = app.notebook_manager.rev_mapping.get(notebook_name, '') + if notebook_id: + url = self.settings.get('base_project_url', '/') + notebook_id + return self.redirect(url) + else: + raise HTTPError(404) + class NotebookRootHandler(AuthenticatedHandler): @authenticate_unless_readonly diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index f8708ac..ee8edcc 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -51,7 +51,7 @@ from .handlers import (LoginHandler, LogoutHandler, ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler, RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler, MainClusterHandler, ClusterProfileHandler, ClusterActionHandler, - FileFindHandler, + FileFindHandler, NotebookRedirectHandler, ) from .nbmanager import NotebookManager from .filenbmanager import FileNotebookManager @@ -85,6 +85,7 @@ from IPython.utils.path import filefind _kernel_id_regex = r"(?P\w+-\w+-\w+-\w+-\w+)" _kernel_action_regex = r"(?Prestart|interrupt)" _notebook_id_regex = r"(?P\w+-\w+-\w+-\w+-\w+)" +_notebook_name_regex = r"(?P.+\.ipynb)" _profile_regex = r"(?P[^\/]+)" # there is almost no text that is invalid _cluster_action_regex = r"(?Pstart|stop)" @@ -135,6 +136,7 @@ class NotebookWebApplication(web.Application): (r"/logout", LogoutHandler), (r"/new", NewHandler), (r"/%s" % _notebook_id_regex, NamedNotebookHandler), + (r"/%s" % _notebook_name_regex, NotebookRedirectHandler), (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler), (r"/%s/print" % _notebook_id_regex, PrintNotebookHandler), (r"/kernels", MainKernelHandler), @@ -169,6 +171,7 @@ class NotebookWebApplication(web.Application): cookie_secret=os.urandom(1024), login_url=url_path_join(base_project_url,'/login'), cookie_name='username-%s' % uuid.uuid4(), + base_project_url = base_project_url, ) # allow custom overrides for the tornado web app.