redirect /edit/ to /files/ if not (utf8) text

Min RK 12 years ago
parent 85fb8e1085
commit c81609f5d6

@ -370,7 +370,8 @@ def json_errors(method):
message = e.log_message
self.log.warn(message)
self.set_status(e.status_code)
self.finish(json.dumps(dict(message=message)))
reply = dict(message=message, reason=e.reason)
self.finish(json.dumps(reply))
except Exception:
self.log.error("Unhandled error in API request", exc_info=True)
status = 500
@ -378,7 +379,7 @@ def json_errors(method):
t, value, tb = sys.exc_info()
self.set_status(status)
tb_text = ''.join(traceback.format_exception(t, value, tb))
reply = dict(message=message, traceback=tb_text)
reply = dict(message=message, reason=None, traceback=tb_text)
self.finish(json.dumps(reply))
else:
return result

@ -282,7 +282,7 @@ class FileContentsManager(ContentsManager):
model['content'] = bcontent.decode('utf8')
except UnicodeError as e:
if format == 'text':
raise web.HTTPError(400, "%s is not UTF-8 encoded" % path)
raise web.HTTPError(400, "%s is not UTF-8 encoded" % path, reason='bad format')
else:
model['format'] = 'text'
@ -345,14 +345,14 @@ class FileContentsManager(ContentsManager):
if os.path.isdir(os_path):
if type_ not in (None, 'directory'):
raise web.HTTPError(400,
u'%s is a directory, not a %s' % (path, type_))
u'%s is a directory, not a %s' % (path, type_), reason='bad type')
model = self._dir_model(path, content=content)
elif type_ == 'notebook' or (type_ is None and path.endswith('.ipynb')):
model = self._notebook_model(path, content=content)
else:
if type_ == 'directory':
raise web.HTTPError(400,
u'%s is not a directory')
u'%s is not a directory', reason='bad type')
model = self._file_model(path, content=content, format=format)
return model

@ -79,6 +79,14 @@ function($,
that.events.trigger("file_loaded.Editor", model);
},
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
);
}
cm.setValue("Error! " + error.message +
"\nSaving disabled.");
that.save_enabled = false;

@ -73,7 +73,7 @@ require([
page.show();
window.onbeforeunload = function () {
if (!editor.codemirror.isClean(editor.generation)) {
if (editor.save_enabled && !editor.codemirror.isClean(editor.generation)) {
return "Unsaved changes will be lost. Close anyway?";
}
};

Loading…
Cancel
Save