##// END OF EJS Templates
add redirect handler for notebooks by name...
MinRK -
Show More
@@ -609,6 +609,20 b' class ShellHandler(AuthenticatedZMQStreamHandler):'
609 # Notebook web service handlers
609 # Notebook web service handlers
610 #-----------------------------------------------------------------------------
610 #-----------------------------------------------------------------------------
611
611
612 class NotebookRedirectHandler(AuthenticatedHandler):
613
614 @authenticate_unless_readonly
615 def get(self, notebook_name):
616 app = self.application
617 if notebook_name.endswith('.ipynb'):
618 notebook_name = notebook_name[:-6]
619 notebook_id = app.notebook_manager.rev_mapping.get(notebook_name, '')
620 if notebook_id:
621 url = self.settings.get('base_project_url', '/') + notebook_id
622 return self.redirect(url)
623 else:
624 raise HTTPError(404)
625
612 class NotebookRootHandler(AuthenticatedHandler):
626 class NotebookRootHandler(AuthenticatedHandler):
613
627
614 @authenticate_unless_readonly
628 @authenticate_unless_readonly
@@ -51,7 +51,7 b' from .handlers import (LoginHandler, LogoutHandler,'
51 ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
51 ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
52 RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler,
52 RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler,
53 MainClusterHandler, ClusterProfileHandler, ClusterActionHandler,
53 MainClusterHandler, ClusterProfileHandler, ClusterActionHandler,
54 FileFindHandler,
54 FileFindHandler, NotebookRedirectHandler,
55 )
55 )
56 from .nbmanager import NotebookManager
56 from .nbmanager import NotebookManager
57 from .filenbmanager import FileNotebookManager
57 from .filenbmanager import FileNotebookManager
@@ -85,6 +85,7 b' from IPython.utils.path import filefind'
85 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
85 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
86 _kernel_action_regex = r"(?P<action>restart|interrupt)"
86 _kernel_action_regex = r"(?P<action>restart|interrupt)"
87 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
87 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
88 _notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)"
88 _profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
89 _profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
89 _cluster_action_regex = r"(?P<action>start|stop)"
90 _cluster_action_regex = r"(?P<action>start|stop)"
90
91
@@ -135,6 +136,7 b' class NotebookWebApplication(web.Application):'
135 (r"/logout", LogoutHandler),
136 (r"/logout", LogoutHandler),
136 (r"/new", NewHandler),
137 (r"/new", NewHandler),
137 (r"/%s" % _notebook_id_regex, NamedNotebookHandler),
138 (r"/%s" % _notebook_id_regex, NamedNotebookHandler),
139 (r"/%s" % _notebook_name_regex, NotebookRedirectHandler),
138 (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
140 (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
139 (r"/%s/print" % _notebook_id_regex, PrintNotebookHandler),
141 (r"/%s/print" % _notebook_id_regex, PrintNotebookHandler),
140 (r"/kernels", MainKernelHandler),
142 (r"/kernels", MainKernelHandler),
@@ -169,6 +171,7 b' class NotebookWebApplication(web.Application):'
169 cookie_secret=os.urandom(1024),
171 cookie_secret=os.urandom(1024),
170 login_url=url_path_join(base_project_url,'/login'),
172 login_url=url_path_join(base_project_url,'/login'),
171 cookie_name='username-%s' % uuid.uuid4(),
173 cookie_name='username-%s' % uuid.uuid4(),
174 base_project_url = base_project_url,
172 )
175 )
173
176
174 # allow custom overrides for the tornado web app.
177 # allow custom overrides for the tornado web app.
General Comments 0
You need to be logged in to leave comments. Login now