mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-05 12:19:58 +08:00
save before download-as
uses `async : false` closes #852 download-as-py still unavailable.
This commit is contained in:
parent
8b94ee2b47
commit
a7f297f8f3
@ -62,10 +62,22 @@ class NotebookHandler(IPythonHandler):
|
||||
# List notebooks in 'path'
|
||||
notebooks = nbm.list_notebooks(path)
|
||||
self.finish(json.dumps(notebooks, default=date_default))
|
||||
return
|
||||
# get and return notebook representation
|
||||
model = nbm.get_notebook_model(name, path)
|
||||
self.set_header(u'Last-Modified', model[u'last_modified'])
|
||||
|
||||
if self.get_argument('download', default='False') == 'True':
|
||||
format = self.get_argument('format', default='json')
|
||||
if format == u'json':
|
||||
self.set_header('Content-Type', 'application/json')
|
||||
raise web.HTTPError(400, "Unrecognized format: %s" % ext)
|
||||
|
||||
self.set_header('Content-Disposition',
|
||||
'attachment; filename="%s"' % name
|
||||
)
|
||||
self.finish(json.dumps(model['content'], default=date_default))
|
||||
else:
|
||||
# get and return notebook representation
|
||||
model = nbm.get_notebook_model(name, path)
|
||||
self.set_header(u'Last-Modified', model[u'last_modified'])
|
||||
self.finish(json.dumps(model, default=date_default))
|
||||
|
||||
@web.authenticated
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
var IPython = (function (IPython) {
|
||||
"use strict";
|
||||
|
||||
var utils = IPython.utils;
|
||||
|
||||
/**
|
||||
* A MenuBar Class to generate the menubar of IPython notebook
|
||||
@ -83,14 +85,29 @@ var IPython = (function (IPython) {
|
||||
});
|
||||
this.element.find('#download_ipynb').click(function () {
|
||||
var notebook_name = IPython.notebook.get_notebook_name();
|
||||
var url = that.baseProjectUrl() + 'api/notebooks' + that.notebookPath() +
|
||||
notebook_name + '?format=json'+ '&download=True';
|
||||
if (IPython.notebook.dirty) {
|
||||
IPython.notebook.save_notebook({async : false});
|
||||
}
|
||||
|
||||
var url = utils.url_path_join(
|
||||
that.baseProjectUrl(),
|
||||
'api/notebooks',
|
||||
that.notebookPath(),
|
||||
notebook_name + '.ipynb?format=json&download=True'
|
||||
);
|
||||
window.location.assign(url);
|
||||
});
|
||||
this.element.find('#download_py').click(function () {
|
||||
var notebook_name = IPython.notebook.get_notebook_name();
|
||||
var url = that.baseProjectUrl() + 'api/notebooks' + that.notebookPath() +
|
||||
notebook_name + '?format=py' + '&download=True';
|
||||
if (IPython.notebook.dirty) {
|
||||
IPython.notebook.save_notebook({async : false});
|
||||
}
|
||||
var url = utils.url_path_join(
|
||||
that.baseProjectUrl(),
|
||||
'api/notebooks',
|
||||
that.notebookPath(),
|
||||
notebook_name + '.ipynb?format=py&download=True'
|
||||
);
|
||||
window.location.assign(url);
|
||||
});
|
||||
this.element.find('#rename_notebook').click(function () {
|
||||
|
@ -1660,7 +1660,7 @@ var IPython = (function (IPython) {
|
||||
*
|
||||
* @method save_notebook
|
||||
*/
|
||||
Notebook.prototype.save_notebook = function () {
|
||||
Notebook.prototype.save_notebook = function (extra_settings) {
|
||||
// Create a JSON model to be sent to the server.
|
||||
var model = {};
|
||||
model.name = this.notebook_name;
|
||||
@ -1680,6 +1680,11 @@ var IPython = (function (IPython) {
|
||||
success : $.proxy(this.save_notebook_success, this, start),
|
||||
error : $.proxy(this.save_notebook_error, this)
|
||||
};
|
||||
if (extra_settings) {
|
||||
for (var key in extra_settings) {
|
||||
settings[key] = extra_settings[key];
|
||||
}
|
||||
}
|
||||
$([IPython.events]).trigger('notebook_saving.Notebook');
|
||||
var url = utils.url_path_join(
|
||||
this.baseProjectUrl(),
|
||||
|
Loading…
Reference in New Issue
Block a user