From 12617792e50e3882617f888a5049ce9900c9c749 2013-10-17 21:07:51 From: Zachary Sailer Date: 2013-10-17 21:07:51 Subject: [PATCH] added folder creation ability using '/-new' --- diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py index f210791..87f2c19 100644 --- a/IPython/html/services/notebooks/nbmanager.py +++ b/IPython/html/services/notebooks/nbmanager.py @@ -81,6 +81,12 @@ class NotebookManager(LoggingConfigurable): allowed_formats = List([u'json',u'py']) + def add_new_folder(self, path=None): + new_path = os.path.join(self.notebook_dir, path) + if not os.path.exists(new_path): + os.makedirs(new_path) + else: + raise web.HTTPError(409, u'Directory already exists or creation permission not allowed.') def load_notebook_names(self, path): """Load the notebook names into memory. diff --git a/IPython/html/tree/handlers.py b/IPython/html/tree/handlers.py index 0d7b8c2..2d8972f 100644 --- a/IPython/html/tree/handlers.py +++ b/IPython/html/tree/handlers.py @@ -77,6 +77,17 @@ class ProjectRedirectHandler(IPythonHandler): url = self.base_project_url + 'tree' self.redirect(url) +class NewFolderHandler(IPythonHandler): + + @authenticate_unless_readonly + def get(self, notebook_path): + nbm = self.notebook_manager + name, path = nbm.named_notebook_path(notebook_path) + nbm.add_new_folder(path) + url = self.base_project_url + 'tree/' + notebook_path + self.redirect(url) + + #----------------------------------------------------------------------------- # URL to handler mappings #----------------------------------------------------------------------------- @@ -85,6 +96,7 @@ class ProjectRedirectHandler(IPythonHandler): _notebook_path_regex = r"(?P.+)" default_handlers = [ + (r"/tree/%s/-new" %_notebook_path_regex, NewFolderHandler), (r"/tree/%s/" % _notebook_path_regex, TreePathRedirectHandler), (r"/tree/%s" % _notebook_path_regex, ProjectPathDashboardHandler), (r"/tree", ProjectDashboardHandler),