handlers.py
105 lines
| 3.3 KiB
| text/x-python
|
PythonLexer
Brian E. Granger
|
r10642 | """Tornado handlers for the tree view. | ||
Brian E. Granger
|
r10641 | |||
Authors: | ||||
* Brian Granger | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
Brian E. Granger
|
r10642 | # Copyright (C) 2011 The IPython Development Team | ||
Brian E. Granger
|
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
|
r11644 | from tornado import web | ||
from ..base.handlers import IPythonHandler | ||||
Zachary Sailer
|
r12990 | from urllib import quote, unquote | ||
Brian E. Granger
|
r10641 | |||
#----------------------------------------------------------------------------- | ||||
Brian E. Granger
|
r10642 | # Handlers | ||
Brian E. Granger
|
r10641 | #----------------------------------------------------------------------------- | ||
class ProjectDashboardHandler(IPythonHandler): | ||||
MinRK
|
r11644 | @web.authenticated | ||
Brian E. Granger
|
r10641 | def get(self): | ||
Brian E. Granger
|
r10651 | self.write(self.render_template('tree.html', | ||
Brian E. Granger
|
r10641 | project=self.project, | ||
project_component=self.project.split('/'), | ||||
Zachary Sailer
|
r12990 | notebook_path= "''" | ||
Brian E. Granger
|
r10641 | )) | ||
Brian E. Granger
|
r10647 | |||
Zachary Sailer
|
r12990 | class ProjectPathDashboardHandler(IPythonHandler): | ||
@authenticate_unless_readonly | ||||
def get(self, notebook_path): | ||||
nbm = self.notebook_manager | ||||
name, path = nbm.named_notebook_path(notebook_path) | ||||
if name != None: | ||||
if path == None: | ||||
self.redirect(self.base_project_url + 'notebooks/' + quote(name)) | ||||
else: | ||||
self.redirect(self.base_project_url + 'notebooks/' + path + quote(name)) | ||||
else: | ||||
project = self.project + '/' + notebook_path | ||||
self.write(self.render_template('tree.html', | ||||
project=project, | ||||
project_component=project.split('/'), | ||||
notebook_path=path, | ||||
Zachary Sailer
|
r13008 | notebook_name=quote(name))) | ||
Zachary Sailer
|
r12990 | |||
class TreeRedirectHandler(IPythonHandler): | ||||
@authenticate_unless_readonly | ||||
def get(self): | ||||
url = self.base_project_url + 'tree' | ||||
self.redirect(url) | ||||
Zachary Sailer
|
r12992 | class TreePathRedirectHandler(IPythonHandler): | ||
@authenticate_unless_readonly | ||||
def get(self, notebook_path): | ||||
url = self.base_project_url + 'tree/'+ notebook_path | ||||
self.redirect(url) | ||||
Zachary Sailer
|
r12990 | class ProjectRedirectHandler(IPythonHandler): | ||
@authenticate_unless_readonly | ||||
def get(self): | ||||
url = self.base_project_url + 'tree' | ||||
self.redirect(url) | ||||
Zachary Sailer
|
r13003 | class NewFolderHandler(IPythonHandler): | ||
@authenticate_unless_readonly | ||||
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) | ||||
Zachary Sailer
|
r13004 | |||
Zachary Sailer
|
r13003 | |||
Brian E. Granger
|
r10647 | #----------------------------------------------------------------------------- | ||
# URL to handler mappings | ||||
#----------------------------------------------------------------------------- | ||||
Zachary Sailer
|
r12990 | _notebook_path_regex = r"(?P<notebook_path>.+)" | ||
default_handlers = [ | ||||
Zachary Sailer
|
r13003 | (r"/tree/%s/-new" %_notebook_path_regex, NewFolderHandler), | ||
Zachary Sailer
|
r12992 | (r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler), | ||
Zachary Sailer
|
r12990 | (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler), | ||
(r"/tree", ProjectDashboardHandler), | ||||
(r"/tree/", TreeRedirectHandler), | ||||
(r"/", ProjectRedirectHandler) | ||||
] | ||||