Custom sort per album
This commit is contained in:
@@ -10,6 +10,7 @@ named ``index.md`` :
|
||||
Title: Another example gallery
|
||||
Thumbnail: test2.jpg
|
||||
Author: John Doe
|
||||
Sort: -name
|
||||
|
||||
And a description with *Markdown* syntax.
|
||||
|
||||
@@ -21,6 +22,8 @@ gallery:
|
||||
represent the gallery.
|
||||
- *Author*: the author of the gallery, if present it is used instead of the
|
||||
author setting.
|
||||
- *Sort*: the sort order for this album. If prefixed with a '-' it will be in
|
||||
reversed order.
|
||||
|
||||
Any additional meta-data is available in the templates. For instance::
|
||||
|
||||
|
||||
@@ -404,26 +404,32 @@ class Album:
|
||||
|
||||
def sort_subdirs(self, albums_sort_attr):
|
||||
if self.subdirs:
|
||||
if albums_sort_attr:
|
||||
root_path = self.path if self.path != '.' else ''
|
||||
if albums_sort_attr.startswith("meta."):
|
||||
meta_key = albums_sort_attr.split(".", 1)[1]
|
||||
|
||||
def sort_key(s):
|
||||
album = self.gallery.albums[join(root_path, s)]
|
||||
return album.meta.get(meta_key, [''])[0]
|
||||
albums_sort_attr = self.settings['albums_sort_attr']
|
||||
reverse = self.settings['albums_sort_reverse']
|
||||
|
||||
if 'sort' in self.meta:
|
||||
albums_sort_attr = self.meta['sort'][0]
|
||||
if albums_sort_attr[0] == '-':
|
||||
albums_sort_attr = albums_sort_attr[1:]
|
||||
reverse = True
|
||||
else:
|
||||
def sort_key(s):
|
||||
album = self.gallery.albums[join(root_path, s)]
|
||||
return getattr(album, albums_sort_attr)
|
||||
reverse = False
|
||||
|
||||
root_path = self.path if self.path != '.' else ''
|
||||
if albums_sort_attr.startswith("meta."):
|
||||
meta_key = albums_sort_attr.split(".", 1)[1]
|
||||
|
||||
def sort_key(s):
|
||||
album = self.gallery.albums[join(root_path, s)]
|
||||
return album.meta.get(meta_key, [''])[0]
|
||||
|
||||
key = natsort_keygen(key=sort_key, alg=ns.LOCALE)
|
||||
else:
|
||||
key = natsort_keygen(alg=ns.LOCALE)
|
||||
def sort_key(s):
|
||||
album = self.gallery.albums[join(root_path, s)]
|
||||
return getattr(album, albums_sort_attr)
|
||||
|
||||
self.subdirs.sort(key=key,
|
||||
reverse=self.settings['albums_sort_reverse'])
|
||||
key = natsort_keygen(key=sort_key, alg=ns.LOCALE)
|
||||
self.subdirs.sort(key=key, reverse=reverse)
|
||||
|
||||
signals.albums_sorted.send(self)
|
||||
|
||||
|
||||
@@ -124,11 +124,12 @@ thumb_size = (280, 210)
|
||||
# Use symbolic links instead of copying the original images
|
||||
# orig_link = False
|
||||
|
||||
# Use symbolic links that are relative to the source directory instead of absolute paths
|
||||
# Use symbolic links that are relative to the source directory instead of
|
||||
# absolute paths
|
||||
# rel_link = False
|
||||
|
||||
# Attribute of Album objects which is used to sort medias (eg 'title'). To sort
|
||||
# on a metadata key, use 'meta.key'.
|
||||
# Attribute of Album objects which is used to sort medias (eg 'title'). To
|
||||
# sort on a metadata key, use 'meta.key'.
|
||||
# albums_sort_attr = 'name'
|
||||
|
||||
# Reverse sort for albums
|
||||
|
||||
Reference in New Issue
Block a user