|
|
|
|
@ -35,13 +35,16 @@ class NotebookHandler(IPythonHandler):
|
|
|
|
|
|
|
|
|
|
@web.authenticated
|
|
|
|
|
def post(self):
|
|
|
|
|
"""post either creates a new notebook if no json data is
|
|
|
|
|
sent to the server, or copies the data and returns a
|
|
|
|
|
copied notebook."""
|
|
|
|
|
nbm = self.notebook_manager
|
|
|
|
|
data=self.request.body
|
|
|
|
|
if data == "":
|
|
|
|
|
notebook_name = nbm.new_notebook()
|
|
|
|
|
else:
|
|
|
|
|
if data:
|
|
|
|
|
data = jsonapi.loads(data)
|
|
|
|
|
notebook_name = nbm.copy_notebook(data['name'])
|
|
|
|
|
else:
|
|
|
|
|
notebook_name = nbm.new_notebook()
|
|
|
|
|
self.finish(jsonapi.dumps({"name": notebook_name}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -49,35 +52,41 @@ class NamedNotebookHandler(IPythonHandler):
|
|
|
|
|
|
|
|
|
|
@web.authenticated
|
|
|
|
|
def get(self, notebook_path):
|
|
|
|
|
"""get renders the notebook template if a name is given, or
|
|
|
|
|
redirects to the '/files/' handler if the name is not given."""
|
|
|
|
|
nbm = self.notebook_manager
|
|
|
|
|
name, path = nbm.named_notebook_path(notebook_path)
|
|
|
|
|
if name != None:
|
|
|
|
|
if name is not None:
|
|
|
|
|
# a .ipynb filename was given
|
|
|
|
|
if not nbm.notebook_exists(name, path):
|
|
|
|
|
raise web.HTTPError(404, u'Notebook does not exist: %s' % name)
|
|
|
|
|
name = nbm.url_encode(name)
|
|
|
|
|
if path == None:
|
|
|
|
|
project = self.project + '/' + name
|
|
|
|
|
else:
|
|
|
|
|
project = self.project + '/' + path +'/'+ name
|
|
|
|
|
path = nbm.url_encode(path)
|
|
|
|
|
if not nbm.notebook_exists(notebook_path):
|
|
|
|
|
raise web.HTTPError(404, u'Notebook does not exist: %s' % name)
|
|
|
|
|
self.write(self.render_template('notebook.html',
|
|
|
|
|
project=project,
|
|
|
|
|
notebook_path=path,
|
|
|
|
|
notebook_name=name,
|
|
|
|
|
kill_kernel=False,
|
|
|
|
|
mathjax_url=self.mathjax_url,
|
|
|
|
|
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,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
url = "/files/" + notebook_path
|
|
|
|
|
self.redirect(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@web.authenticated
|
|
|
|
|
def post(self, notebook_path):
|
|
|
|
|
"""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."""
|
|
|
|
|
nbm = self.notebook_manager
|
|
|
|
|
data = self.request.body
|
|
|
|
|
if data == "":
|
|
|
|
|
notebook_name = nbm.new_notebook(notebook_path)
|
|
|
|
|
else:
|
|
|
|
|
if data:
|
|
|
|
|
data = jsonapi.loads(data)
|
|
|
|
|
notebook_name = nbm.copy_notebook(data['name'], notebook_path)
|
|
|
|
|
else:
|
|
|
|
|
notebook_name = nbm.new_notebook(notebook_path)
|
|
|
|
|
self.finish(jsonapi.dumps({"name": notebook_name}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -90,5 +99,5 @@ _notebook_path_regex = r"(?P<notebook_path>.+)"
|
|
|
|
|
|
|
|
|
|
default_handlers = [
|
|
|
|
|
(r"/notebooks/%s" % _notebook_path_regex, NamedNotebookHandler),
|
|
|
|
|
(r"/notebooks/", NotebookHandler)
|
|
|
|
|
]
|
|
|
|
|
(r"/notebooks/", NotebookHandler),
|
|
|
|
|
]
|