##// END OF EJS Templates
fix `--notebook-dir` configurable when there is no trailing slash
fix `--notebook-dir` configurable when there is no trailing slash

File last commit:

r13055:299dc731
r13066:99675b00
Show More
handlers.py
77 lines | 2.5 KiB | text/x-python | PythonLexer
Brian E. Granger
Splitting handlers into different files....
r10642 """Tornado handlers for the tree view.
Brian E. Granger
Adding new files.
r10641
Authors:
* Brian Granger
"""
#-----------------------------------------------------------------------------
Brian E. Granger
Splitting handlers into different files....
r10642 # Copyright (C) 2011 The IPython Development Team
Brian E. Granger
Adding new files.
r10641 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
MinRK
Simplify Tree handlers...
r13055 import os
Brian E. Granger
Adding new files.
r10641
MinRK
remove notebook read-only view...
r11644 from tornado import web
from ..base.handlers import IPythonHandler
MinRK
Simplify Tree handlers...
r13055 from ..utils import url_path_join, path2url, url2path
Brian E. Granger
Adding new files.
r10641
#-----------------------------------------------------------------------------
Brian E. Granger
Splitting handlers into different files....
r10642 # Handlers
Brian E. Granger
Adding new files.
r10641 #-----------------------------------------------------------------------------
MinRK
Simplify Tree handlers...
r13055 class TreeHandler(IPythonHandler):
"""Render the tree view, listing notebooks, clusters, etc."""
Brian E. Granger
Adding new files.
r10641
MinRK
remove notebook read-only view...
r11644 @web.authenticated
MinRK
Simplify Tree handlers...
r13055 def get(self, notebook_path=""):
Zachary Sailer
manual rebase tree/handlers.py
r12990 nbm = self.notebook_manager
name, path = nbm.named_notebook_path(notebook_path)
Zachary Sailer
fixing broken links from recent changes....
r13033 if name is not None:
MinRK
Simplify Tree handlers...
r13055 # is a notebook, redirect to notebook handler
url = url_path_join(self.base_project_url, 'notebooks', path, name)
self.redirect(url)
Zachary Sailer
manual rebase tree/handlers.py
r12990 else:
MinRK
Simplify Tree handlers...
r13055 location = nbm.get_os_path(path=path)
if not os.path.exists(location):
# no such directory, 404
raise web.HTTPError(404)
Zachary Sailer
manual rebase tree/handlers.py
r12990 self.write(self.render_template('tree.html',
MinRK
Simplify Tree handlers...
r13055 project=self.project_dir,
tree_url_path=path2url(location),
Zachary Sailer
manual rebase tree/handlers.py
r12990 notebook_path=path,
MinRK
Simplify Tree handlers...
r13055 ))
Zachary Sailer
manual rebase tree/handlers.py
r12990
class TreeRedirectHandler(IPythonHandler):
MinRK
Simplify Tree handlers...
r13055 """Redirect a request to the corresponding tree URL"""
Zachary Sailer
fixing path redirects, cleaning path logic
r12992
Zachary Sailer
rebase master- eliminate read-only
r13014 @web.authenticated
MinRK
Simplify Tree handlers...
r13055 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)
Zachary Sailer
manual rebase tree/handlers.py
r12990 self.redirect(url)
Zachary Sailer
added folder creation ability using '/-new'
r13003
Brian E. Granger
More work on the handlers
r10647 #-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
Zachary Sailer
manual rebase tree/handlers.py
r12990 _notebook_path_regex = r"(?P<notebook_path>.+)"
default_handlers = [
MinRK
Simplify Tree handlers...
r13055 (r"/tree/%s/" % _notebook_path_regex, TreeRedirectHandler),
(r"/tree/%s" % _notebook_path_regex, TreeHandler),
Zachary Sailer
manual rebase tree/handlers.py
r12990 (r"/tree/", TreeRedirectHandler),
MinRK
Simplify Tree handlers...
r13055 (r"/tree", TreeHandler),
(r"/", TreeRedirectHandler),
Zachary Sailer
manual rebase tree/handlers.py
r12990 ]