##// END OF EJS Templates
Case insensitive sorting in the dashboard....
Thomas Kluyver -
Show More
@@ -18,6 +18,7 b' Authors:'
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19
19
20 import io
20 import io
21 import locale
21 import os
22 import os
22 import glob
23 import glob
23 import shutil
24 import shutil
@@ -31,6 +32,10 b' from IPython.utils.py3compat import getcwd'
31 from IPython.utils import tz
32 from IPython.utils import tz
32 from IPython.html.utils import is_hidden, to_os_path
33 from IPython.html.utils import is_hidden, to_os_path
33
34
35 def sort_key(item):
36 """Case-insensitive, locale aware sorting."""
37 return locale.strxfrm(item['name'].lower())
38
34 #-----------------------------------------------------------------------------
39 #-----------------------------------------------------------------------------
35 # Classes
40 # Classes
36 #-----------------------------------------------------------------------------
41 #-----------------------------------------------------------------------------
@@ -189,7 +194,7 b' class FileNotebookManager(NotebookManager):'
189 except IOError:
194 except IOError:
190 pass
195 pass
191 dirs.append(model)
196 dirs.append(model)
192 dirs = sorted(dirs, key=lambda item: item['name'])
197 dirs = sorted(dirs, key=sort_key)
193 return dirs
198 return dirs
194
199
195 # TODO: Remove this after we create the contents web service and directories are
200 # TODO: Remove this after we create the contents web service and directories are
@@ -230,7 +235,7 b' class FileNotebookManager(NotebookManager):'
230 path = path.strip('/')
235 path = path.strip('/')
231 notebook_names = self.get_notebook_names(path)
236 notebook_names = self.get_notebook_names(path)
232 notebooks = [self.get_notebook(name, path, content=False) for name in notebook_names]
237 notebooks = [self.get_notebook(name, path, content=False) for name in notebook_names]
233 notebooks = sorted(notebooks, key=lambda item: item['name'])
238 notebooks = sorted(notebooks, key=sort_key)
234 return notebooks
239 return notebooks
235
240
236 def get_notebook(self, name, path='', content=True):
241 def get_notebook(self, name, path='', content=True):
@@ -101,7 +101,10 b' class APITest(NotebookTestBase):'
101 ('foo', 'name with spaces'),
101 ('foo', 'name with spaces'),
102 ('foo', u'unicodé'),
102 ('foo', u'unicodé'),
103 ('foo/bar', 'baz'),
103 ('foo/bar', 'baz'),
104 (u'å b', u'ç d')
104 ('ordering', 'A'),
105 ('ordering', 'b'),
106 ('ordering', 'C'),
107 (u'å b', u'ç d'),
105 ]
108 ]
106 hidden_dirs = ['.hidden', '__pycache__']
109 hidden_dirs = ['.hidden', '__pycache__']
107
110
@@ -160,6 +163,11 b' class APITest(NotebookTestBase):'
160 expected = [ u'a.ipynb', u'b.ipynb', u'name with spaces.ipynb', u'unicodé.ipynb']
163 expected = [ u'a.ipynb', u'b.ipynb', u'name with spaces.ipynb', u'unicodé.ipynb']
161 expected = { normalize('NFC', name) for name in expected }
164 expected = { normalize('NFC', name) for name in expected }
162 self.assertEqual(nbnames, expected)
165 self.assertEqual(nbnames, expected)
166
167 nbs = notebooks_only(self.nb_api.list('ordering').json())
168 nbnames = [n['name'] for n in nbs]
169 expected = ['A.ipynb', 'b.ipynb', 'C.ipynb']
170 self.assertEqual(nbnames, expected)
163
171
164 def test_list_dirs(self):
172 def test_list_dirs(self):
165 dirs = dirs_only(self.nb_api.list().json())
173 dirs = dirs_only(self.nb_api.list().json())
General Comments 0
You need to be logged in to leave comments. Login now