##// END OF EJS Templates
simplified named_notebook_path implementation...
simplified named_notebook_path implementation Also updated the tests

File last commit:

r13018:96956c19
r13027:4e4ce404
Show More
handlers.py
94 lines | 2.9 KiB | text/x-python | PythonLexer
Brian E. Granger
Splitting handlers into different files....
r10642 """Tornado handlers for the live notebook 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
#-----------------------------------------------------------------------------
import os
from tornado import web
Brian E. Granger
Splitting handlers into different files....
r10642 HTTPError = web.HTTPError
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 from zmq.utils import jsonapi
Brian E. Granger
Adding new files.
r10641
MinRK
remove notebook read-only view...
r11644 from ..base.handlers import IPythonHandler
Brian E. Granger
Splitting handlers into different files....
r10642 from ..utils import url_path_join
Zachary Sailer
allow notebook names with spaces
r13008 from urllib import quote
Brian E. Granger
Adding new files.
r10641
#-----------------------------------------------------------------------------
Brian E. Granger
Splitting handlers into different files....
r10642 # Handlers
Brian E. Granger
Adding new files.
r10641 #-----------------------------------------------------------------------------
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 class NotebookHandler(IPythonHandler):
Brian E. Granger
Adding new files.
r10641
@web.authenticated
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 def post(self):
Zachary Sailer
Change new/copy URLS to POST requests
r13017 nbm = self.notebook_manager
data=self.request.body
if data == "":
notebook_name = nbm.new_notebook()
else:
data = jsonapi.loads(data)
notebook_name = nbm.copy_notebook(data['name'])
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 self.finish(jsonapi.dumps({"name": notebook_name}))
Brian E. Granger
Splitting handlers into different files....
r10642
Brian E. Granger
Adding new files.
r10641
class NamedNotebookHandler(IPythonHandler):
MinRK
remove notebook read-only view...
r11644 @web.authenticated
Zachary Sailer
manual rebase notebook/handlers.py
r12981 def get(self, notebook_path):
Brian E. Granger
Adding new files.
r10641 nbm = self.notebook_manager
Zachary Sailer
manual rebase notebook/handlers.py
r12981 name, path = nbm.named_notebook_path(notebook_path)
Zachary Sailer
allow notebook names with spaces
r13008 if name != None:
Zachary Sailer
path with spaces completely fixed
r13013 name = nbm.url_encode(name)
Zachary Sailer
manual rebase notebook/handlers.py
r12981 if path == None:
project = self.project + '/' + name
else:
project = self.project + '/' + path +'/'+ name
Zachary Sailer
path with spaces completely fixed
r13013 path = nbm.url_encode(path)
Zachary Sailer
add contents web service api
r13006 if not nbm.notebook_exists(notebook_path):
Zachary Sailer
allow spaces in notebook path
r13012 raise web.HTTPError(404, u'Notebook does not exist: %s' % name)
Brian E. Granger
Creating override.css for each page....
r10723 self.write(self.render_template('notebook.html',
Zachary Sailer
manual rebase notebook/handlers.py
r12981 project=project,
notebook_path=path,
notebook_name=name,
Brian E. Granger
Adding new files.
r10641 kill_kernel=False,
mathjax_url=self.mathjax_url,
)
)
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016
Zachary Sailer
standard model changes
r13011 @web.authenticated
def post(self, notebook_path):
Zachary Sailer
Change new/copy URLS to POST requests
r13017 nbm = self.notebook_manager
data = self.request.body
if data == "":
notebook_name = nbm.new_notebook(notebook_path)
else:
data = jsonapi.loads(data)
notebook_name = nbm.copy_notebook(data['name'], notebook_path)
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 self.finish(jsonapi.dumps({"name": notebook_name}))
Brian E. Granger
Adding new files.
r10641
Brian E. Granger
More work on the handlers
r10647 #-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
Zachary Sailer
manual rebase notebook/handlers.py
r12981 _notebook_path_regex = r"(?P<notebook_path>.+)"
Brian E. Granger
More work on the handlers
r10647
default_handlers = [
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 (r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler),
(r"/notebooks/", NotebookHandler)
Brian E. Granger
More work on the handlers
r10647 ]