notebook/IPython/html/tree/handlers.py

104 lines
3.1 KiB
Python
Raw Normal View History

"""Tornado handlers for the tree view.
2013-05-03 02:15:32 +08:00
Authors:
* Brian Granger
"""
#-----------------------------------------------------------------------------
# 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
#-----------------------------------------------------------------------------
from tornado import web
from ..base.handlers import IPythonHandler
2013-07-04 01:47:39 +08:00
from urllib import quote, unquote
2013-05-03 02:15:32 +08:00
#-----------------------------------------------------------------------------
# Handlers
2013-05-03 02:15:32 +08:00
#-----------------------------------------------------------------------------
class ProjectDashboardHandler(IPythonHandler):
@web.authenticated
2013-05-03 02:15:32 +08:00
def get(self):
self.write(self.render_template('tree.html',
2013-05-03 02:15:32 +08:00
project=self.project,
project_component=self.project.split('/'),
2013-07-04 01:47:39 +08:00
notebook_path= "''"
2013-05-03 02:15:32 +08:00
))
2013-05-16 01:55:43 +08:00
2013-07-04 01:47:39 +08:00
class ProjectPathDashboardHandler(IPythonHandler):
2013-07-26 03:57:14 +08:00
@web.authenticated
2013-07-04 01:47:39 +08:00
def get(self, notebook_path):
nbm = self.notebook_manager
name, path = nbm.named_notebook_path(notebook_path)
if name != None:
2013-07-26 01:38:08 +08:00
self.redirect(self.base_project_url + 'notebooks/' + notebook_path)
2013-07-04 01:47:39 +08:00
else:
2013-07-26 01:38:08 +08:00
path = nbm.url_encode(path)
2013-07-04 01:47:39 +08:00
project = self.project + '/' + notebook_path
self.write(self.render_template('tree.html',
project=project,
project_component=project.split('/'),
notebook_path=path,
2013-07-23 13:56:29 +08:00
notebook_name=name))
2013-07-04 01:47:39 +08:00
class TreeRedirectHandler(IPythonHandler):
2013-07-26 03:57:14 +08:00
@web.authenticated
2013-07-04 01:47:39 +08:00
def get(self):
url = self.base_project_url + 'tree'
self.redirect(url)
class TreePathRedirectHandler(IPythonHandler):
2013-07-26 03:57:14 +08:00
@web.authenticated
def get(self, notebook_path):
url = self.base_project_url + 'tree/'+ notebook_path
self.redirect(url)
2013-07-04 01:47:39 +08:00
class ProjectRedirectHandler(IPythonHandler):
2013-07-26 03:57:14 +08:00
@web.authenticated
2013-07-04 01:47:39 +08:00
def get(self):
url = self.base_project_url + 'tree'
self.redirect(url)
class NewFolderHandler(IPythonHandler):
2013-07-26 03:57:14 +08:00
@web.authenticated
def get(self, notebook_path):
nbm = self.notebook_manager
name, path = nbm.named_notebook_path(notebook_path)
nbm.add_new_folder(path)
url = self.base_project_url + 'tree/' + notebook_path
self.redirect(url)
2013-07-20 05:06:26 +08:00
2013-05-16 01:55:43 +08:00
#-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
2013-07-04 01:47:39 +08:00
_notebook_path_regex = r"(?P<notebook_path>.+)"
default_handlers = [
(r"/tree/%s/-new" %_notebook_path_regex, NewFolderHandler),
(r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler),
2013-07-04 01:47:39 +08:00
(r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler),
(r"/tree", ProjectDashboardHandler),
(r"/tree/", TreeRedirectHandler),
(r"/", ProjectRedirectHandler)
]