diff --git a/IPython/html/services/contents/filemanager.py b/IPython/html/services/contents/filemanager.py index ef4acf4..a2f35ee 100644 --- a/IPython/html/services/contents/filemanager.py +++ b/IPython/html/services/contents/filemanager.py @@ -309,10 +309,10 @@ class FileContentsManager(ContentsManager): """Save the file model and return the model with no content.""" path = path.strip('/') - if 'content' not in model: - raise web.HTTPError(400, u'No file content provided') if 'type' not in model: raise web.HTTPError(400, u'No file type provided') + if 'content' not in model and model['type'] != 'directory': + raise web.HTTPError(400, u'No file content provided') # One checkpoint should always exist if self.file_exists(name, path) and not self.list_checkpoints(name, path): diff --git a/IPython/html/services/contents/manager.py b/IPython/html/services/contents/manager.py index 871c363..2a8c776 100644 --- a/IPython/html/services/contents/manager.py +++ b/IPython/html/services/contents/manager.py @@ -165,16 +165,16 @@ class ContentsManager(LoggingConfigurable): path = path.strip('/') if model is None: model = {} - if 'content' not in model: + if 'content' not in model and model.get('type', None) != 'directory': if ext == '.ipynb': metadata = current.new_metadata(name=u'') model['content'] = current.new_notebook(metadata=metadata) - model.setdefault('type', 'notebook') - model.setdefault('format', 'json') + model['type'] = 'notebook' + model['format'] = 'json' else: model['content'] = '' - model.setdefault('type', 'file') - model.setdefault('format', 'text') + model['type'] = 'file' + model['format'] = 'text' if 'name' not in model: model['name'] = self.increment_filename('Untitled' + ext, path) @@ -185,7 +185,7 @@ class ContentsManager(LoggingConfigurable): def copy(self, from_name, to_name=None, path=''): """Copy an existing file and return its new model. - If to_name not specified, increment `from_name-Copy#.ipynb`. + If to_name not specified, increment `from_name-Copy#.ext`. """ path = path.strip('/') model = self.get_model(from_name, path)