more named_notebook_path cleanup

named_notebook_path now returns path with leading and trailing slashes.
Work with @Zsailer
Paul Ivanov 13 years ago committed by MinRK
parent fd7a64ff38
commit a083ad1fd7

@ -105,10 +105,7 @@ class NotebookHandler(IPythonHandler):
notebook_name = nbm.save_new_notebook(body, notebook_path=notebook_path, name=name, format=format)
else:
notebook_name = nbm.new_notebook(notebook_path=notebook_path)
if notebook_path==None:
self.set_header('Location', nbm.notebook_dir + '/'+ notebook_name)
else:
self.set_header('Location', nbm.notebook_dir + '/'+ notebook_path + '/' + notebook_name)
self.set_header('Location', nbm.notebook_dir + notebook_path + notebook_name)
model = nbm.notebook_model(notebook_name, notebook_path)
self.finish(jsonapi.dumps(model))
else:

@ -44,7 +44,8 @@ class NotebookManager(LoggingConfigurable):
def named_notebook_path(self, notebook_path):
"""Given a notebook_path name, returns a (name, path) tuple, where
name is a .ipynb file, and path is the directory for the file.
name is a .ipynb file, and path is the directory for the file, which
*always* starts *and* ends with a '/' character.
Parameters
----------
@ -59,10 +60,12 @@ class NotebookManager(LoggingConfigurable):
the path to the directory which contains the notebook
"""
names = notebook_path.split('/')
names = [n for n in names if n != ''] # remove duplicate splits
name = names[-1]
if name.endswith(".ipynb"):
name = name
names = [''] + names
if names and names[-1].endswith(".ipynb"):
name = names[-1]
path = "/".join(names[:-1]) + '/'
else:
name = None

@ -39,10 +39,11 @@ class TestNotebookManager(TestCase):
# doesn't end with ipynb, should just be path
name, path = nm.named_notebook_path('hello')
self.assertEqual(name, None)
self.assertEqual(path, 'hello/')
self.assertEqual(path, '/hello/')
name, path = nm.named_notebook_path('/')
self.assertEqual(name, None)
self.assertEqual(path, '/')
name, path = nm.named_notebook_path('hello.ipynb')
self.assertEqual(name, 'hello.ipynb')
@ -55,5 +56,9 @@ class TestNotebookManager(TestCase):
name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
self.assertEqual(name, 'hello.ipynb')
self.assertEqual(path, '/this/is/a/path/')
name, path = nm.named_notebook_path('path/without/leading/slash/hello.ipynb')
self.assertEqual(name, 'hello.ipynb')
self.assertEqual(path, '/path/without/leading/slash/')

Loading…
Cancel
Save