##// END OF EJS Templates
Merge pull request #8000 from mathieu1/dashboard-nb-rename-dialog...
Merge pull request #8000 from mathieu1/dashboard-nb-rename-dialog Fix rename issues in dashboard

File last commit:

r18751:a4801a71
r20776:318462d4 merge
Show More
handlers.py
122 lines | 4.1 KiB | text/x-python | PythonLexer
MinRK
rename notebooks service to contents service...
r17524 """Tornado handlers for the sessions web service."""
Zachary Sailer
manual rebase - add sessions web service
r12985
MinRK
rename notebooks service to contents service...
r17524 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Zachary Sailer
manual rebase - add sessions web service
r12985
Zachary Sailer
changes after session manager code review
r13057 import json
Zachary Sailer
manual rebase - add sessions web service
r12985
Zachary Sailer
changes after session manager code review
r13057 from tornado import web
Brian E. Granger
Improving tests and setting of Location header.
r13116
Zachary Sailer
changes after session manager code review
r13057 from ...base.handlers import IPythonHandler, json_errors
Brian E. Granger
Improving tests and setting of Location header.
r13116 from IPython.utils.jsonutil import date_default
MinRK
escape URLs in Location headers
r13132 from IPython.html.utils import url_path_join, url_escape
Jessica B. Hamrick
Handle NoSuchKernel errors more gracefully
r18059 from IPython.kernel.kernelspec import NoSuchKernel
Zachary Sailer
manual rebase - add sessions web service
r12985
class SessionRootHandler(IPythonHandler):
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
rebase master- eliminate read-only
r13014 @web.authenticated
Zachary Sailer
changes after session manager code review
r13057 @json_errors
Zachary Sailer
manual rebase - add sessions web service
r12985 def get(self):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Return a list of running sessions
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
sessions = sm.list_sessions()
Zachary Sailer
changes after session manager code review
r13057 self.finish(json.dumps(sessions, default=date_default))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985 @web.authenticated
Zachary Sailer
changes after session manager code review
r13057 @json_errors
Zachary Sailer
manual rebase - add sessions web service
r12985 def post(self):
Dale Jung
API: Allow NotebookManagers to control kernel startup dir. #5468
r16052 # Creates a new session
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 #(unless a session already exists for the named nb)
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
MinRK
rename notebooks service to contents service...
r17524 cm = self.contents_manager
km = self.kernel_manager
Thomas Kluyver
Add kernel name to sessions REST API...
r17222
Zachary Sailer
changes after session manager code review
r13057 model = self.get_json_body()
if model is None:
Zachary Sailer
adding to test_kernels_api.py...
r13058 raise web.HTTPError(400, "No JSON data provided")
Zachary Sailer
changes after session manager code review
r13057 try:
path = model['notebook']['path']
except KeyError:
Thomas Kluyver
Add kernel name to sessions REST API...
r17222 raise web.HTTPError(400, "Missing field in JSON data: notebook.path")
try:
kernel_name = model['kernel']['name']
except KeyError:
MinRK
allow kernel_name to be undefined in requests...
r18022 self.log.debug("No kernel name specified, using default kernel")
kernel_name = None
Thomas Kluyver
Add kernel name to sessions REST API...
r17222
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Check to see if session exists
Min RK
remove notebook['name'] from sessions
r18751 if sm.session_exists(path=path):
model = sm.get_session(path=path)
Zachary Sailer
session manager restructuring...
r13035 else:
Jessica B. Hamrick
Handle NoSuchKernel errors more gracefully
r18059 try:
Min RK
remove notebook['name'] from sessions
r18751 model = sm.create_session(path=path, kernel_name=kernel_name)
Jessica B. Hamrick
Handle NoSuchKernel errors more gracefully
r18059 except NoSuchKernel:
Jessica B. Hamrick
Better user experience when kernel isn't found
r18063 msg = ("The '%s' kernel is not available. Please pick another "
"suitable kernel instead, or install that kernel." % kernel_name)
Jessica B. Hamrick
More descriptive short message
r18069 status_msg = '%s not found' % kernel_name
Jessica B. Hamrick
Return a proper JSON object
r18065 self.log.warn('Kernel not found: %s' % kernel_name)
self.set_status(501)
self.finish(json.dumps(dict(message=msg, short_message=status_msg)))
return
Jessica B. Hamrick
Handle NoSuchKernel errors more gracefully
r18059
MinRK
remove base_kernel_url
r15310 location = url_path_join(self.base_url, 'api', 'sessions', model['id'])
MinRK
escape URLs in Location headers
r13132 self.set_header('Location', url_escape(location))
Thomas Kluyver
Fix some HTTP status codes in sessions API
r13095 self.set_status(201)
Zachary Sailer
changes after session manager code review
r13057 self.finish(json.dumps(model, default=date_default))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985 class SessionHandler(IPythonHandler):
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 SUPPORTED_METHODS = ('GET', 'PATCH', 'DELETE')
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
rebase master- eliminate read-only
r13014 @web.authenticated
Zachary Sailer
changes after session manager code review
r13057 @json_errors
Zachary Sailer
manual rebase - add sessions web service
r12985 def get(self, session_id):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Returns the JSON model for a single session
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
MinRK
review pass on Sessions API
r13101 model = sm.get_session(session_id=session_id)
Zachary Sailer
changes after session manager code review
r13057 self.finish(json.dumps(model, default=date_default))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 @web.authenticated
Zachary Sailer
changes after session manager code review
r13057 @json_errors
Zachary Sailer
Add 'patch' to session & notebook, rename working
r12997 def patch(self, session_id):
Zachary Sailer
session manager restructuring...
r13035 # Currently, this handler is strictly for renaming notebooks
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
Zachary Sailer
changes after session manager code review
r13057 model = self.get_json_body()
if model is None:
Thomas Kluyver
Clean up sessions code from static analysis
r13096 raise web.HTTPError(400, "No JSON data provided")
Zachary Sailer
changes after session manager code review
r13057 changes = {}
if 'notebook' in model:
notebook = model['notebook']
if 'path' in notebook:
changes['path'] = notebook['path']
MinRK
review pass on Sessions API
r13101
Zachary Sailer
changes after session manager code review
r13057 sm.update_session(session_id, **changes)
MinRK
review pass on Sessions API
r13101 model = sm.get_session(session_id=session_id)
Zachary Sailer
changes after session manager code review
r13057 self.finish(json.dumps(model, default=date_default))
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985 @web.authenticated
Zachary Sailer
changes after session manager code review
r13057 @json_errors
Zachary Sailer
manual rebase - add sessions web service
r12985 def delete(self, session_id):
Zachary Sailer
cleaning nb handlers, adding doc-strings/comments
r13036 # Deletes the session with given session_id
Zachary Sailer
manual rebase - add sessions web service
r12985 sm = self.session_manager
Jessica B. Hamrick
More informative error messages
r18214 try:
sm.delete_session(session_id)
except KeyError:
# the kernel was deleted but the session wasn't!
raise web.HTTPError(410, "Kernel deleted before session")
Zachary Sailer
fixed shutdown button refresh on dashboard
r12996 self.set_status(204)
self.finish()
Zachary Sailer
removing debug logs
r13009
Zachary Sailer
manual rebase - add sessions web service
r12985
#-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
_session_id_regex = r"(?P<session_id>\w+-\w+-\w+-\w+-\w+)"
default_handlers = [
Zachary Sailer
add tests to notebooks api...
r13059 (r"/api/sessions/%s" % _session_id_regex, SessionHandler),
(r"/api/sessions", SessionRootHandler)
Zachary Sailer
manual rebase - add sessions web service
r12985 ]