diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 5d76b74..c156826 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -679,41 +679,44 @@ class NotebookHandler(IPythonHandler): self.set_status(204) self.finish() -class NotebookCheckpointHandler(AuthenticatedHandler): - SUPPORTED_METHODS = ('GET', 'POST', 'PUT', 'DELETE') +class NotebookCheckpointsHandler(AuthenticatedHandler): + + SUPPORTED_METHODS = ('GET', 'POST') @web.authenticated def get(self, notebook_id): """get lists checkpoints for a notebook""" nbm = self.application.notebook_manager checkpoints = nbm.list_checkpoints(notebook_id) - self.finish(checkpoints) + data = jsonapi.dumps(checkpoints, default=date_default) + self.finish(data) @web.authenticated def post(self, notebook_id): + """post creates a new checkpoint""" + nbm = self.application.notebook_manager + checkpoint = nbm.create_checkpoint(notebook_id) + data = jsonapi.dumps(checkpoint, default=date_default) + self.finish(data) + + +class ModifyNotebookCheckpointsHandler(AuthenticatedHandler): + + SUPPORTED_METHODS = ('POST', 'DELETE') + + @web.authenticated + def post(self, notebook_id, checkpoint_id): """post restores a notebook from a checkpoint""" nbm = self.application.notebook_manager - checkpoint_id = self.get_argument('checkpoint', None) nbm.restore_checkpoint(notebook_id, checkpoint_id) self.set_status(204) self.finish() @web.authenticated - def put(self, notebook_id): - """put saves the notebook, and creates a new checkpoint""" - nbm = self.application.notebook_manager - format = self.get_argument('format', default='json') - name = self.get_argument('name', default=None) - nbm.save_notebook(notebook_id, self.request.body, name=name, format=format) - checkpoint = nbm.create_checkpoint(notebook_id) - self.finish(checkpoint) - - @web.authenticated - def delete(self, notebook_id): + def delete(self, notebook_id, checkpoint_id): """delete clears a checkpoint for a given notebook""" nbm = self.application.notebook_manager - checkpoint_id = self.get_argument('checkpoint', None) nbm.delte_checkpoint(notebook_id, checkpoint_id) self.set_status(204) self.finish() diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 536e480..28e5fa8 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -68,9 +68,9 @@ from .handlers import (LoginHandler, LogoutHandler, ProjectDashboardHandler, NewHandler, NamedNotebookHandler, MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, StdinHandler, ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler, - AuthenticatedFileHandler, MainClusterHandler, ClusterProfileHandler, - ClusterActionHandler, FileFindHandler, - NotebookRedirectHandler, NotebookCheckpointHandler, + NotebookRedirectHandler, NotebookCheckpointsHandler, ModifyNotebookCheckpointsHandler, + AuthenticatedFileHandler, FileFindHandler, + MainClusterHandler, ClusterProfileHandler, ClusterActionHandler, ) from .nbmanager import NotebookManager from .filenbmanager import FileNotebookManager @@ -105,6 +105,7 @@ _kernel_id_regex = r"(?P\w+-\w+-\w+-\w+-\w+)" _kernel_action_regex = r"(?Prestart|interrupt)" _notebook_id_regex = r"(?P\w+-\w+-\w+-\w+-\w+)" _notebook_name_regex = r"(?P.+\.ipynb)" +_checkpoint_id_regex = r"(?P[\w-]+)" _profile_regex = r"(?P[^\/]+)" # there is almost no text that is invalid _cluster_action_regex = r"(?Pstart|stop)" @@ -162,7 +163,10 @@ class NotebookWebApplication(web.Application): (r"/kernels/%s/stdin" % _kernel_id_regex, StdinHandler), (r"/notebooks", NotebookRootHandler), (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler), - (r"/notebooks/%s/checkpoint" % _notebook_id_regex, NotebookCheckpointHandler), + (r"/notebooks/%s/checkpoints" % _notebook_id_regex, NotebookCheckpointsHandler), + (r"/notebooks/%s/checkpoints/%s" % (_notebook_id_regex, _checkpoint_id_regex), + ModifyNotebookCheckpointsHandler + ), (r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}), (r"/clusters", MainClusterHandler), (r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler),