Case insensitive sorting in the dashboard.

Closes gh-5151
Thomas Kluyver 12 years ago
parent c1e8ddc64e
commit 4fe9f8d057

@ -18,6 +18,7 @@ Authors:
#-----------------------------------------------------------------------------
import io
import locale
import os
import glob
import shutil
@ -31,6 +32,10 @@ from IPython.utils.py3compat import getcwd
from IPython.utils import tz
from IPython.html.utils import is_hidden, to_os_path
def sort_key(item):
"""Case-insensitive, locale aware sorting."""
return locale.strxfrm(item['name'].lower())
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
@ -189,7 +194,7 @@ class FileNotebookManager(NotebookManager):
except IOError:
pass
dirs.append(model)
dirs = sorted(dirs, key=lambda item: item['name'])
dirs = sorted(dirs, key=sort_key)
return dirs
# TODO: Remove this after we create the contents web service and directories are
@ -230,7 +235,7 @@ class FileNotebookManager(NotebookManager):
path = path.strip('/')
notebook_names = self.get_notebook_names(path)
notebooks = [self.get_notebook(name, path, content=False) for name in notebook_names]
notebooks = sorted(notebooks, key=lambda item: item['name'])
notebooks = sorted(notebooks, key=sort_key)
return notebooks
def get_notebook(self, name, path='', content=True):

@ -101,7 +101,10 @@ class APITest(NotebookTestBase):
('foo', 'name with spaces'),
('foo', u'unicodé'),
('foo/bar', 'baz'),
(u'å b', u'ç d')
('ordering', 'A'),
('ordering', 'b'),
('ordering', 'C'),
(u'å b', u'ç d'),
]
hidden_dirs = ['.hidden', '__pycache__']
@ -160,6 +163,11 @@ class APITest(NotebookTestBase):
expected = [ u'a.ipynb', u'b.ipynb', u'name with spaces.ipynb', u'unicodé.ipynb']
expected = { normalize('NFC', name) for name in expected }
self.assertEqual(nbnames, expected)
nbs = notebooks_only(self.nb_api.list('ordering').json())
nbnames = [n['name'] for n in nbs]
expected = ['A.ipynb', 'b.ipynb', 'C.ipynb']
self.assertEqual(nbnames, expected)
def test_list_dirs(self):
dirs = dirs_only(self.nb_api.list().json())

Loading…
Cancel
Save