From 69711f88b221d76ca89ff36ef124cf886c83cf02 2013-10-17 21:55:00 From: MinRK Date: 2013-10-17 21:55:00 Subject: [PATCH] use 'id' for checkpoint ID key rather than redundant checkpoint.checkpoint_id --- diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index 346518c..891c9fd 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -278,7 +278,7 @@ class FileNotebookManager(NotebookManager): # clear checkpoints for checkpoint in self.list_checkpoints(name, path): - checkpoint_id = checkpoint['checkpoint_id'] + checkpoint_id = checkpoint['id'] cp_path = self.get_checkpoint_path(checkpoint_id, name, path) if os.path.isfile(cp_path): self.log.debug("Unlinking checkpoint %s", cp_path) @@ -315,7 +315,7 @@ class FileNotebookManager(NotebookManager): # Move the checkpoints old_checkpoints = self.list_checkpoints(old_name, old_path) for cp in old_checkpoints: - checkpoint_id = cp['checkpoint_id'] + checkpoint_id = cp['id'] old_cp_path = self.get_checkpoint_path(checkpoint_id, old_name, old_path) new_cp_path = self.get_checkpoint_path(checkpoint_id, new_name, new_path) if os.path.isfile(old_cp_path): @@ -346,7 +346,7 @@ class FileNotebookManager(NotebookManager): stats = os.stat(cp_path) last_modified = tz.utcfromtimestamp(stats.st_mtime) info = dict( - checkpoint_id = checkpoint_id, + id = checkpoint_id, last_modified = last_modified, ) return info diff --git a/IPython/html/services/notebooks/handlers.py b/IPython/html/services/notebooks/handlers.py index 14f530f..7a4b1d8 100644 --- a/IPython/html/services/notebooks/handlers.py +++ b/IPython/html/services/notebooks/handlers.py @@ -180,9 +180,9 @@ class NotebookCheckpointsHandler(IPythonHandler): nbm = self.notebook_manager checkpoint = nbm.create_checkpoint(name, path) data = json.dumps(checkpoint, default=date_default) - location = url_path_join(self.base_project_url, u'/api/notebooks', - path, name, 'checkpoints', checkpoint[u'checkpoint_id']) - self.set_header(u'Location', location) + location = url_path_join(self.base_project_url, 'api/notebooks', + path, name, 'checkpoints', checkpoint['id']) + self.set_header('Location', location) self.set_status(201) self.finish(data) diff --git a/IPython/html/services/notebooks/tests/test_notebooks_api.py b/IPython/html/services/notebooks/tests/test_notebooks_api.py index ec7b1f5..42de40e 100644 --- a/IPython/html/services/notebooks/tests/test_notebooks_api.py +++ b/IPython/html/services/notebooks/tests/test_notebooks_api.py @@ -229,8 +229,8 @@ class APITest(NotebookTestBase): r = self.nb_api.new_checkpoint('a.ipynb', 'foo') self.assertEqual(r.status_code, 201) cp1 = r.json() - self.assertEqual(set(cp1), {'checkpoint_id', 'last_modified'}) - self.assertEqual(r.headers['Location'].split('/')[-1], cp1['checkpoint_id']) + self.assertEqual(set(cp1), {'id', 'last_modified'}) + self.assertEqual(r.headers['Location'].split('/')[-1], cp1['id']) # Modify it nbcontent = jsonapi.loads(resp.text)['content'] @@ -252,14 +252,14 @@ class APITest(NotebookTestBase): self.assertEqual(nb.worksheets[0].cells[0].source, 'Created by test') # Restore cp1 - r = self.nb_api.restore_checkpoint('a.ipynb', 'foo', cp1['checkpoint_id']) + r = self.nb_api.restore_checkpoint('a.ipynb', 'foo', cp1['id']) self.assertEqual(r.status_code, 204) nbcontent = self.nb_api.read('a.ipynb', 'foo').json()['content'] nb = to_notebook_json(nbcontent) self.assertEqual(nb.worksheets, []) # Delete cp1 - r = self.nb_api.delete_checkpoint('a.ipynb', 'foo', cp1['checkpoint_id']) + r = self.nb_api.delete_checkpoint('a.ipynb', 'foo', cp1['id']) self.assertEqual(r.status_code, 204) cps = self.nb_api.get_checkpoints('a.ipynb', 'foo').json() self.assertEqual(cps, []) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index ef8fb28..16d9297 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -2009,7 +2009,7 @@ var IPython = (function (IPython) { var found = false; for (var i = 0; i < this.checkpoints.length; i++) { var existing = this.checkpoints[i]; - if (existing.checkpoint_id == checkpoint.checkpoint_id) { + if (existing.id == checkpoint.id) { found = true; this.checkpoints[i] = checkpoint; break; @@ -2149,7 +2149,7 @@ var IPython = (function (IPython) { Revert : { class : "btn-danger", click : function () { - that.restore_checkpoint(checkpoint.checkpoint_id); + that.restore_checkpoint(checkpoint.id); } }, Cancel : {}