Implement album sorting

This adds an 'albums_sort_attr' configuration modeled off of the
'medias_sort_attr'.  It defaults to the existing behavior of sorting
sub-albums by directory name.  It allows sort by any metadata attribute
stored in the album metadata file.

The existing album sort test wasn't really verifying album sorting
behavior, so I just re-wrote the whole thing to include tests for the
old behavior and new.

This should resolve issue #121
This commit is contained in:
Craig Gallek
2016-01-18 17:29:28 -05:00
parent b11cb28ff3
commit 589eec0d21
8 changed files with 54 additions and 6 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View File

@@ -0,0 +1 @@
Title: 01 First title alphabetically

View File

@@ -15,7 +15,7 @@ REF = {
'title': 'An example gallery',
'name': 'dir1',
'thumbnail': 'dir1/test1/thumbnails/11.tn.jpg',
'subdirs': ['test1', 'test2'],
'subdirs': ['test1', 'test2', 'test3'],
'medias': [],
},
'dir1/test1': {
@@ -34,6 +34,13 @@ REF = {
'subdirs': [],
'medias': ['21.jpg', '22.jpg', 'archlinux-kiss-1024x640.png'],
},
'dir1/test3': {
'title': '01 First title alphabetically',
'name': 'test3',
'thumbnail': 'test3/thumbnails/3.tn.jpg',
'subdirs': [],
'medias': ['3.jpg'],
},
'dir2': {
'title': 'Another example gallery with a very long name',
'name': 'dir2',
@@ -165,10 +172,29 @@ def test_album_medias(settings):
def test_albums_sort(settings):
gal = Gallery(settings, ncpu=1)
album = REF['dir1']
subdirs = list(album['subdirs'])
settings['albums_sort_reverse'] = False
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
a.sort_subdirs('')
assert [alb.name for alb in a.albums] == subdirs
settings['albums_sort_reverse'] = True
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
assert [im.filename for im in a.images] == list(reversed(album['medias']))
a.sort_subdirs('')
assert [alb.name for alb in a.albums] == list(reversed(subdirs))
titles = [im.title for im in a.albums]
titles.sort()
settings['albums_sort_reverse'] = False
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
a.sort_subdirs('title')
assert [im.title for im in a.albums] == titles
settings['albums_sort_reverse'] = True
a = Album('dir1', settings, album['subdirs'], album['medias'], gal)
a.sort_subdirs('title')
assert [im.title for im in a.albums] == list(reversed(titles))
def test_medias_sort(settings):