mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
cleanup old, unused /notebooks/foo
API methods
these have moved to `/api/notebooks`
This commit is contained in:
parent
4e12521082
commit
75e14424c6
@ -17,10 +17,10 @@ Authors:
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from tornado import web
|
||||
HTTPError = web.HTTPError
|
||||
from zmq.utils import jsonapi
|
||||
|
||||
|
||||
from ..base.handlers import IPythonHandler
|
||||
from ..services.notebooks.handlers import _notebook_path_regex, _path_regex
|
||||
@ -34,33 +34,14 @@ from urllib import quote
|
||||
|
||||
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:
|
||||
data = jsonapi.loads(data)
|
||||
notebook_name = nbm.copy_notebook(data['name'])
|
||||
else:
|
||||
notebook_name = nbm.new_notebook()
|
||||
self.finish(jsonapi.dumps({"name": notebook_name}))
|
||||
|
||||
|
||||
class NamedNotebookHandler(IPythonHandler):
|
||||
|
||||
@web.authenticated
|
||||
def get(self, path='', name=None):
|
||||
"""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
|
||||
if name is None:
|
||||
url = url_path_join(self.base_project_url, 'files', path)
|
||||
self.redirect(url)
|
||||
return
|
||||
|
||||
raise web.HTTPError(500, "This shouldn't be accessible: %s" % self.request.uri)
|
||||
|
||||
# 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))
|
||||
@ -75,20 +56,17 @@ class NamedNotebookHandler(IPythonHandler):
|
||||
)
|
||||
)
|
||||
|
||||
@web.authenticated
|
||||
def post(self, path='', name=None):
|
||||
"""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."""
|
||||
class NotebookRedirectHandler(IPythonHandler):
|
||||
def get(self, path=''):
|
||||
nbm = self.notebook_manager
|
||||
data = self.request.body
|
||||
if data:
|
||||
data = jsonapi.loads(data)
|
||||
notebook_name = nbm.copy_notebook(data['name'], notebook_path)
|
||||
if nbm.path_exists(path):
|
||||
# it's a *directory*, redirect to /tree
|
||||
url = url_path_join(self.base_project_url, 'tree', path)
|
||||
else:
|
||||
notebook_name = nbm.new_notebook(notebook_path)
|
||||
self.finish(jsonapi.dumps({"name": notebook_name}))
|
||||
|
||||
# otherwise, redirect to /files
|
||||
# TODO: This should check if it's actually a file
|
||||
url = url_path_join(self.base_project_url, 'files', path)
|
||||
self.redirect(url)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# URL to handler mappings
|
||||
@ -96,8 +74,7 @@ class NamedNotebookHandler(IPythonHandler):
|
||||
|
||||
|
||||
default_handlers = [
|
||||
(r"/notebooks/?%s" % _notebook_path_regex, NamedNotebookHandler),
|
||||
(r"/notebooks/?%s" % _path_regex, NamedNotebookHandler),
|
||||
(r"/notebooks/?", NotebookHandler),
|
||||
(r"/notebooks/?%s" % _notebook_path_regex, NotebookHandler),
|
||||
(r"/notebooks/?%s" % _path_regex, NotebookRedirectHandler),
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user