##// END OF EJS Templates
adjust definition of 'path' in notebooks...
adjust definition of 'path' in notebooks never includes leading or trailing '/'

File last commit:

r13067:8c61a47c
r13067:8c61a47c
Show More
handlers.py
103 lines | 3.4 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
MinRK
adjust definition of 'path' in notebooks...
r13067 from ..services.notebooks.handlers import _notebook_path_regex, _path_regex
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):
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 """post either creates a new notebook if no json data is
sent to the server, or copies the data and returns a
copied notebook."""
Zachary Sailer
Change new/copy URLS to POST requests
r13017 nbm = self.notebook_manager
data=self.request.body
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 if data:
Zachary Sailer
Change new/copy URLS to POST requests
r13017 data = jsonapi.loads(data)
notebook_name = nbm.copy_notebook(data['name'])
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 else:
notebook_name = nbm.new_notebook()
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
MinRK
adjust definition of 'path' in notebooks...
r13067 def get(self, path='', name=None):
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 """get renders the notebook template if a name is given, or
redirects to the '/files/' handler if the name is not given."""
Brian E. Granger
Adding new files.
r10641 nbm = self.notebook_manager
MinRK
adjust definition of 'path' in notebooks...
r13067 if name is None:
url = url_path_join(self.base_project_url, 'files', path)
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 self.redirect(url)
MinRK
adjust definition of 'path' in notebooks...
r13067 return
Paul Ivanov
named_notebook_path: consistent usage convention
r13029
MinRK
adjust definition of 'path' in notebooks...
r13067 # a .ipynb filename was given
if not nbm.notebook_exists(name, path):
raise web.HTTPError(404, u'Notebook does not exist: %s/%s' % (path, name))
name = nbm.url_encode(name)
path = nbm.url_encode(path)
self.write(self.render_template('notebook.html',
project=self.project_dir,
notebook_path=path,
notebook_name=name,
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
MinRK
adjust definition of 'path' in notebooks...
r13067 def post(self, path='', name=None):
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 """post either creates a new notebook if no json data is
sent to the server, or copies the data and returns a
copied notebook in the location given by 'notebook_path."""
Zachary Sailer
Change new/copy URLS to POST requests
r13017 nbm = self.notebook_manager
data = self.request.body
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 if data:
Zachary Sailer
Change new/copy URLS to POST requests
r13017 data = jsonapi.loads(data)
notebook_name = nbm.copy_notebook(data['name'], notebook_path)
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 else:
notebook_name = nbm.new_notebook(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
#-----------------------------------------------------------------------------
default_handlers = [
MinRK
adjust definition of 'path' in notebooks...
r13067 (r"/notebooks/?%s" % _notebook_path_regex, NamedNotebookHandler),
(r"/notebooks/?%s" % _path_regex, NamedNotebookHandler),
(r"/notebooks/?", NotebookHandler),
Zachary Sailer
fixing broken links from recent changes....
r13033 ]