Skip to content

Commit

Permalink
Merge edit-redirect fix for 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Sep 16, 2015
2 parents ccf11df + 2b835ca commit 0a8096a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
5 changes: 5 additions & 0 deletions IPython/html/files/handlers.py
Expand Up @@ -40,6 +40,11 @@ def get(self, path):
cur_mime = mimetypes.guess_type(name)[0]
if cur_mime is not None:
self.set_header('Content-Type', cur_mime)
else:
if model['format'] == 'base64':
self.set_header('Content-Type', 'application/octet-stream')
else:
self.set_header('Content-Type', 'text/plain')

if model['format'] == 'base64':
b64_bytes = model['content'].encode('ascii')
Expand Down
12 changes: 7 additions & 5 deletions IPython/html/services/contents/filemanager.py
Expand Up @@ -277,18 +277,20 @@ def _file_model(self, path, content=True, format=None):
model['type'] = 'file'

os_path = self._get_os_path(path)
model['mimetype'] = mimetypes.guess_type(os_path)[0]

if content:
content, format = self._read_file(os_path, format)
default_mime = {
'text': 'text/plain',
'base64': 'application/octet-stream'
}[format]
if model['mimetype'] is None:
default_mime = {
'text': 'text/plain',
'base64': 'application/octet-stream'
}[format]
model['mimetype'] = default_mime

model.update(
content=content,
format=format,
mimetype=mimetypes.guess_type(os_path)[0] or default_mime,
)

return model
Expand Down
3 changes: 0 additions & 3 deletions IPython/html/services/contents/handlers.py
Expand Up @@ -52,9 +52,6 @@ def validate_model(model, expect_content):
)

maybe_none_keys = ['content', 'format']
if model['type'] == 'file':
# mimetype should be populated only for file models
maybe_none_keys.append('mimetype')
if expect_content:
errors = [key for key in maybe_none_keys if model[key] is None]
if errors:
Expand Down
15 changes: 3 additions & 12 deletions IPython/html/static/edit/js/editor.js
Expand Up @@ -90,19 +90,10 @@ function($,
}).catch(
function(error) {
that.events.trigger("file_load_failed.Editor", error);
if (((error.xhr||{}).responseJSON||{}).reason === 'bad format') {
window.location = utils.url_path_join(
that.base_url,
'files',
that.file_path
);
} else {
console.warn('Error while loading: the error was:')
console.warn(error)
}
console.warn('Error loading: ', error);
cm.setValue("Error! " + error.message +
"\nSaving disabled.\nSee Console for more details.");
cm.setOption('readOnly','nocursor')
cm.setOption('readOnly','nocursor');
that.save_enabled = false;
}
);
Expand Down Expand Up @@ -186,7 +177,7 @@ function($,
Editor.prototype._clean_state = function(){
var clean = this.codemirror.isClean(this.generation);
if (clean === this.clean){
return
return;
} else {
this.clean = clean;
}
Expand Down
7 changes: 7 additions & 0 deletions IPython/html/static/tree/js/notebooklist.js
Expand Up @@ -532,6 +532,13 @@ define([
icon = 'running_' + icon;
}
var uri_prefix = NotebookList.uri_prefixes[model.type];
if (model.type === 'file' &&
model.mimetype && model.mimetype.substr(0,5) !== 'text/'
) {
// send text/unidentified files to editor, others go to raw viewer
uri_prefix = 'files';
}

item.find(".item_icon").addClass(icon).addClass('icon-fixed-width');
var link = item.find("a.item_link")
.attr('href',
Expand Down

0 comments on commit 0a8096a

Please sign in to comment.