2013-05-03 03:19:21 +08:00
|
|
|
"""Tornado handlers for the tree view.
|
2013-05-03 02:15:32 +08:00
|
|
|
|
|
|
|
Authors:
|
|
|
|
|
|
|
|
* Brian Granger
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
2013-05-03 03:19:21 +08:00
|
|
|
# Copyright (C) 2011 The IPython Development Team
|
2013-05-03 02:15:32 +08:00
|
|
|
#
|
|
|
|
# Distributed under the terms of the BSD License. The full license is in
|
|
|
|
# the file COPYING, distributed as part of this software.
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Imports
|
|
|
|
#-----------------------------------------------------------------------------
|
2013-08-25 18:10:19 +08:00
|
|
|
import os
|
2013-05-03 02:15:32 +08:00
|
|
|
|
2013-07-24 04:03:03 +08:00
|
|
|
from tornado import web
|
2013-12-20 05:01:00 +08:00
|
|
|
from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
|
2013-10-19 06:12:23 +08:00
|
|
|
from ..utils import url_path_join, path2url, url2path, url_escape
|
2013-05-03 02:15:32 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
2013-05-03 03:19:21 +08:00
|
|
|
# Handlers
|
2013-05-03 02:15:32 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2013-08-25 18:10:19 +08:00
|
|
|
class TreeHandler(IPythonHandler):
|
|
|
|
"""Render the tree view, listing notebooks, clusters, etc."""
|
2013-05-03 02:15:32 +08:00
|
|
|
|
2013-07-24 04:03:03 +08:00
|
|
|
@web.authenticated
|
2013-10-08 03:19:14 +08:00
|
|
|
def get(self, path='', name=None):
|
2013-10-11 15:22:27 +08:00
|
|
|
path = path.strip('/')
|
2013-07-04 01:47:39 +08:00
|
|
|
nbm = self.notebook_manager
|
2013-08-14 05:58:40 +08:00
|
|
|
if name is not None:
|
2013-08-25 18:10:19 +08:00
|
|
|
# is a notebook, redirect to notebook handler
|
2013-10-19 06:12:23 +08:00
|
|
|
url = url_escape(url_path_join(
|
|
|
|
self.base_project_url, 'notebooks', path, name
|
|
|
|
))
|
|
|
|
self.log.debug("Redirecting %s to %s", self.request.path, url)
|
2013-08-25 18:10:19 +08:00
|
|
|
self.redirect(url)
|
2013-07-04 01:47:39 +08:00
|
|
|
else:
|
2013-10-08 03:19:14 +08:00
|
|
|
if not nbm.path_exists(path=path):
|
2013-08-25 18:10:19 +08:00
|
|
|
# no such directory, 404
|
|
|
|
raise web.HTTPError(404)
|
2013-07-04 01:47:39 +08:00
|
|
|
self.write(self.render_template('tree.html',
|
2013-08-25 18:10:19 +08:00
|
|
|
project=self.project_dir,
|
2013-10-08 03:19:14 +08:00
|
|
|
tree_url_path=path,
|
2013-07-04 01:47:39 +08:00
|
|
|
notebook_path=path,
|
2013-08-25 18:10:19 +08:00
|
|
|
))
|
2013-07-04 01:47:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TreeRedirectHandler(IPythonHandler):
|
2013-08-25 18:10:19 +08:00
|
|
|
"""Redirect a request to the corresponding tree URL"""
|
2013-07-04 05:19:37 +08:00
|
|
|
|
2013-07-26 03:57:14 +08:00
|
|
|
@web.authenticated
|
2013-10-08 03:19:14 +08:00
|
|
|
def get(self, path=''):
|
2013-10-19 06:12:23 +08:00
|
|
|
url = url_escape(url_path_join(
|
|
|
|
self.base_project_url, 'tree', path.strip('/')
|
|
|
|
))
|
|
|
|
self.log.debug("Redirecting %s to %s", self.request.path, url)
|
2013-07-04 01:47:39 +08:00
|
|
|
self.redirect(url)
|
|
|
|
|
2013-07-18 01:54:19 +08:00
|
|
|
|
2013-05-16 01:55:43 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# URL to handler mappings
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2013-07-04 01:47:39 +08:00
|
|
|
default_handlers = [
|
2013-12-20 05:01:00 +08:00
|
|
|
(r"/tree%s" % notebook_path_regex, TreeHandler),
|
|
|
|
(r"/tree%s" % path_regex, TreeHandler),
|
2013-08-25 18:10:19 +08:00
|
|
|
(r"/tree", TreeHandler),
|
|
|
|
(r"/", TreeRedirectHandler),
|
2013-07-04 01:47:39 +08:00
|
|
|
]
|