##// END OF EJS Templates
more named_notebook_path cleanup...
Paul Ivanov -
Show More
@@ -105,10 +105,7 b' class NotebookHandler(IPythonHandler):'
105 notebook_name = nbm.save_new_notebook(body, notebook_path=notebook_path, name=name, format=format)
105 notebook_name = nbm.save_new_notebook(body, notebook_path=notebook_path, name=name, format=format)
106 else:
106 else:
107 notebook_name = nbm.new_notebook(notebook_path=notebook_path)
107 notebook_name = nbm.new_notebook(notebook_path=notebook_path)
108 if notebook_path==None:
108 self.set_header('Location', nbm.notebook_dir + notebook_path + notebook_name)
109 self.set_header('Location', nbm.notebook_dir + '/'+ notebook_name)
110 else:
111 self.set_header('Location', nbm.notebook_dir + '/'+ notebook_path + '/' + notebook_name)
112 model = nbm.notebook_model(notebook_name, notebook_path)
109 model = nbm.notebook_model(notebook_name, notebook_path)
113 self.finish(jsonapi.dumps(model))
110 self.finish(jsonapi.dumps(model))
114 else:
111 else:
@@ -44,7 +44,8 b' class NotebookManager(LoggingConfigurable):'
44
44
45 def named_notebook_path(self, notebook_path):
45 def named_notebook_path(self, notebook_path):
46 """Given a notebook_path name, returns a (name, path) tuple, where
46 """Given a notebook_path name, returns a (name, path) tuple, where
47 name is a .ipynb file, and path is the directory for the file.
47 name is a .ipynb file, and path is the directory for the file, which
48 *always* starts *and* ends with a '/' character.
48
49
49 Parameters
50 Parameters
50 ----------
51 ----------
@@ -59,10 +60,12 b' class NotebookManager(LoggingConfigurable):'
59 the path to the directory which contains the notebook
60 the path to the directory which contains the notebook
60 """
61 """
61 names = notebook_path.split('/')
62 names = notebook_path.split('/')
63 names = [n for n in names if n != ''] # remove duplicate splits
62
64
63 name = names[-1]
65 names = [''] + names
64 if name.endswith(".ipynb"):
66
65 name = name
67 if names and names[-1].endswith(".ipynb"):
68 name = names[-1]
66 path = "/".join(names[:-1]) + '/'
69 path = "/".join(names[:-1]) + '/'
67 else:
70 else:
68 name = None
71 name = None
@@ -39,10 +39,11 b' class TestNotebookManager(TestCase):'
39 # doesn't end with ipynb, should just be path
39 # doesn't end with ipynb, should just be path
40 name, path = nm.named_notebook_path('hello')
40 name, path = nm.named_notebook_path('hello')
41 self.assertEqual(name, None)
41 self.assertEqual(name, None)
42 self.assertEqual(path, 'hello/')
42 self.assertEqual(path, '/hello/')
43
43
44 name, path = nm.named_notebook_path('/')
44 name, path = nm.named_notebook_path('/')
45 self.assertEqual(name, None)
45 self.assertEqual(name, None)
46 self.assertEqual(path, '/')
46
47
47 name, path = nm.named_notebook_path('hello.ipynb')
48 name, path = nm.named_notebook_path('hello.ipynb')
48 self.assertEqual(name, 'hello.ipynb')
49 self.assertEqual(name, 'hello.ipynb')
@@ -55,5 +56,9 b' class TestNotebookManager(TestCase):'
55 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
56 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
56 self.assertEqual(name, 'hello.ipynb')
57 self.assertEqual(name, 'hello.ipynb')
57 self.assertEqual(path, '/this/is/a/path/')
58 self.assertEqual(path, '/this/is/a/path/')
59
60 name, path = nm.named_notebook_path('path/without/leading/slash/hello.ipynb')
61 self.assertEqual(name, 'hello.ipynb')
62 self.assertEqual(path, '/path/without/leading/slash/')
58
63
59
64
General Comments 0
You need to be logged in to leave comments. Login now