Implemented metadata for notebook format.

This commit is contained in:
Brian E. Granger 2011-08-19 15:44:32 -07:00
parent 7e7a6ab50b
commit ea8b4de42d
2 changed files with 11 additions and 7 deletions

View File

@ -147,10 +147,10 @@ class NotebookManager(LoggingConfigurable):
if name is None:
try:
name = nb.name
name = nb.metadata.name
except AttributeError:
raise web.HTTPError(400)
nb.name = name
nb.metadata.name = name
notebook_id = self.new_notebook_id(name)
self.save_notebook_object(notebook_id, nb)
@ -167,7 +167,7 @@ class NotebookManager(LoggingConfigurable):
raise web.HTTPError(400)
if name is not None:
nb.name = name
nb.metadata.name = name
self.save_notebook_object(notebook_id, nb)
def save_notebook_object(self, notebook_id, nb):
@ -176,7 +176,7 @@ class NotebookManager(LoggingConfigurable):
raise web.HTTPError(404)
old_name = self.mapping[notebook_id]
try:
new_name = nb.name
new_name = nb.metadata.name
except AttributeError:
raise web.HTTPError(400)
path = self.get_path_by_name(new_name)

View File

@ -21,6 +21,7 @@ var IPython = (function (IPython) {
this.kernel = null;
this.dirty = false;
this.msg_cell_map = {};
this.metadata = {};
this.style();
this.create_elements();
this.bind_events();
@ -711,6 +712,8 @@ var IPython = (function (IPython) {
// Always delete cell 0 as they get renumbered as they are deleted.
this.delete_cell(0);
};
// Save the metadata
this.metadata = data.metadata;
// Only handle 1 worksheet for now.
var worksheet = data.worksheets[0];
if (worksheet !== undefined) {
@ -744,7 +747,8 @@ var IPython = (function (IPython) {
};
data = {
// Only handle 1 worksheet for now.
worksheets : [{cells:cell_array}]
worksheets : [{cells:cell_array}],
metadata : this.metadata
}
return data
};
@ -755,7 +759,7 @@ var IPython = (function (IPython) {
var nbname = IPython.save_widget.get_notebook_name();
// We may want to move the name/id/nbformat logic inside toJSON?
var data = this.toJSON();
data.name = nbname;
data.metadata.name = nbname;
data.nbformat = 2;
// We do the call with settings so we can set cache to false.
var settings = {
@ -805,7 +809,7 @@ var IPython = (function (IPython) {
this.insert_code_cell_after();
};
IPython.save_widget.status_save();
IPython.save_widget.set_notebook_name(data.name);
IPython.save_widget.set_notebook_name(data.metadata.name);
this.start_kernel();
this.dirty = false;
// fromJSON always selects the last cell inserted. We need to wait