Skip to content

Commit

Permalink
Merge pull request #507 from dsschult/sort_signed
Browse files Browse the repository at this point in the history
Allow sorting by negative numbers
  • Loading branch information
saimn authored Jan 18, 2024
2 parents bdbefe1 + 1c2cb06 commit 27e10d4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def sort_key(s):
continue
return ""

key = natsort_keygen(key=sort_key, alg=ns.LOCALE)
key = natsort_keygen(key=sort_key, alg=ns.SIGNED|ns.LOCALE)
self.subdirs.sort(key=key, reverse=reverse)

signals.albums_sorted.send(self)
Expand All @@ -530,11 +530,11 @@ def sort_medias(self, medias_sort_attr):
elif medias_sort_attr.startswith("meta."):
meta_key = medias_sort_attr.split(".", 1)[1]
key = natsort_keygen(
key=lambda s: s.meta.get(meta_key, [""])[0], alg=ns.LOCALE
key=lambda s: s.meta.get(meta_key, [""])[0], alg=ns.SIGNED|ns.LOCALE
)
else:
key = natsort_keygen(
key=lambda s: getattr(s, medias_sort_attr), alg=ns.LOCALE
key=lambda s: getattr(s, medias_sort_attr), alg=ns.SIGNED|ns.LOCALE
)

self.medias.sort(key=key, reverse=self.settings["medias_sort_reverse"])
Expand Down
2 changes: 1 addition & 1 deletion tests/sample/pictures/dir1/test2/21.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Title: in"title"
Order: 01
Order: -10

in"description
3 changes: 2 additions & 1 deletion tests/sample/pictures/dir1/test2/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Order: 01
Order: -10
PartialOrder: 01
3 changes: 1 addition & 2 deletions tests/test_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ def test_albums_sort(settings):
a.sort_subdirs("title")
assert [im.title for im in a.albums] == list(reversed(titles))

orders = ["01", "02", "03"]
orders.sort()
orders = ["-10", "02", "03"]
settings["albums_sort_reverse"] = False
a = Album("dir1", settings, album["subdirs"], album["medias"], gal)
a.sort_subdirs("meta.order")
Expand Down

0 comments on commit 27e10d4

Please sign in to comment.