Improvements to file uploaded, mime types and .py reader.

* The .py notebook reader now uses that ast module to split
  a plain python file into blocks. These blocks become cells in
  the notebook.
* Proper mime types are used for xml (application/xml), json
  (application/json) and python (application/x-python).
* Other fixes to file uploading.
Brian E. Granger 15 years ago
parent 458c48b229
commit ad84abcf36

@ -41,12 +41,12 @@ class NamedNotebookHandler(web.RequestHandler):
class KernelHandler(web.RequestHandler):
def get(self):
self.write(json.dumps(self.application.kernel_ids))
self.finish(json.dumps(self.application.kernel_ids))
def post(self):
kernel_id = self.application.start_kernel()
self.set_header('Location', '/'+kernel_id)
self.write(json.dumps(kernel_id))
self.finish(json.dumps(kernel_id))
class KernelActionHandler(web.RequestHandler):
@ -58,6 +58,7 @@ class KernelActionHandler(web.RequestHandler):
if action == 'restart':
new_kernel_id = self.application.restart_kernel(kernel_id)
self.write(json.dumps(new_kernel_id))
self.finish()
class ZMQStreamHandler(websocket.WebSocketHandler):
@ -83,7 +84,7 @@ class NotebookRootHandler(web.RequestHandler):
def get(self):
nbm = self.application.notebook_manager
files = nbm.list_notebooks()
self.write(json.dumps(files))
self.finish(json.dumps(files))
def post(self):
nbm = self.application.notebook_manager
@ -95,7 +96,7 @@ class NotebookRootHandler(web.RequestHandler):
else:
notebook_id = nbm.new_notebook()
self.set_header('Location', '/'+notebook_id)
self.write(json.dumps(notebook_id))
self.finish(json.dumps(notebook_id))
class NotebookHandler(web.RequestHandler):
@ -110,10 +111,10 @@ class NotebookHandler(web.RequestHandler):
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Disposition','attachment; filename=%s.json' % name)
elif format == u'xml':
self.set_header('Content-Type', 'text/xml')
self.set_header('Content-Type', 'application/xml')
self.set_header('Content-Disposition','attachment; filename=%s.ipynb' % name)
elif format == u'py':
self.set_header('Content-Type', 'text/plain')
self.set_header('Content-Type', 'application/x-python')
self.set_header('Content-Disposition','attachment; filename=%s.py' % name)
self.set_header('Last-Modified', last_mod)
self.finish(data)

@ -559,11 +559,12 @@ var IPython = (function (IPython) {
data.id = notebook_id
// We do the call with settings so we can set cache to false.
var settings = {
processData : false,
cache : false,
type : "PUT",
data : JSON.stringify(data),
success : $.proxy(this.notebook_saved,this)
processData : false,
cache : false,
type : "PUT",
data : JSON.stringify(data),
headers : {'Content-Type': 'application/json'},
success : $.proxy(this.notebook_saved,this)
};
IPython.save_widget.status_saving();
$.ajax("/notebooks/" + notebook_id, settings);

@ -191,12 +191,21 @@ var IPython = (function (IPython) {
var nbname = item.find('.item_name > input').attr('value');
var nbformat = item.data('nbformat');
var nbdata = item.data('nbdata');
var content_type = 'text/plain';
if (nbformat === 'xml') {
content_type = 'application/xml';
} else if (nbformat === 'json') {
content_type = 'application/json';
} else if (nbformat === 'py') {
content_type = 'application/x-python';
};
var settings = {
processData : false,
cache : false,
type : "POST",
dataType : "json",
type : 'POST',
dataType : 'json',
data : nbdata,
headers : {'Content-Type': content_type},
success : function (data, status, xhr) {
that.add_link(data, nbname, item);
that.add_delete_button(item);
@ -204,7 +213,7 @@ var IPython = (function (IPython) {
};
var qs = $.param({name:nbname, format:nbformat});
$.ajax("/notebooks?" + qs, settings);
$.ajax('/notebooks?' + qs, settings);
});
var cancel_button = $('<button>Cancel</button>').button().
click(function (e) {

Loading…
Cancel
Save