Video watchlist: strip dirty titles when sorting (leading-space fix)
'Holy Marvels with Dennis Quaid' is stored with a leading space in the shows table, so the watchlist sort key fell to ' holy marvels…' — and a leading space sorts before 'a', jumping it to the top. .strip() the sort key so dirty titles sort by their real first letter.
This commit is contained in:
parent
49714a59ea
commit
5711963a6f
2 changed files with 10 additions and 6 deletions
|
|
@ -2044,8 +2044,10 @@ class VideoDatabase:
|
||||||
if sort == "added": # opt-in: explicit follows (have a date) newest-first
|
if sort == "added": # opt-in: explicit follows (have a date) newest-first
|
||||||
items.sort(key=lambda it: (it.get("date_added") or ""), reverse=True)
|
items.sort(key=lambda it: (it.get("date_added") or ""), reverse=True)
|
||||||
else: # "default" / "title": alphabetical by name — a manual follow is no more
|
else: # "default" / "title": alphabetical by name — a manual follow is no more
|
||||||
# special than an auto-added airing show, so they sort together A–Z
|
# special than an auto-added airing show, so they sort together A–Z.
|
||||||
items.sort(key=lambda it: (it.get("sort_title") or it.get("title") or "").lower())
|
# .strip() guards against dirty titles (e.g. a leading space from the
|
||||||
|
# scan, which would otherwise sort before 'a').
|
||||||
|
items.sort(key=lambda it: (it.get("sort_title") or it.get("title") or "").strip().lower())
|
||||||
total = len(items)
|
total = len(items)
|
||||||
total_pages = max(1, (total + limit - 1) // limit)
|
total_pages = max(1, (total + limit - 1) // limit)
|
||||||
page = min(page, total_pages)
|
page = min(page, total_pages)
|
||||||
|
|
|
||||||
|
|
@ -851,11 +851,13 @@ def test_query_watchlist_default_sort_is_alphabetical(db):
|
||||||
db.add_to_watchlist("show", 1, "Welcome to Widows Bay")
|
db.add_to_watchlist("show", 1, "Welcome to Widows Bay")
|
||||||
db.add_to_watchlist("show", 2, "From")
|
db.add_to_watchlist("show", 2, "From")
|
||||||
db.add_to_watchlist("show", 3, "Andor")
|
db.add_to_watchlist("show", 3, "Andor")
|
||||||
titles = [it["title"] for it in db.query_watchlist("show")["items"]]
|
db.add_to_watchlist("show", 4, " Holy Marvels with Dennis Quaid") # dirty leading space
|
||||||
assert titles == ["Andor", "From", "Welcome to Widows Bay"]
|
titles = [it["title"].strip() for it in db.query_watchlist("show")["items"]]
|
||||||
|
# a leading-space title must NOT jump the queue — sorts under H
|
||||||
|
assert titles == ["Andor", "From", "Holy Marvels with Dennis Quaid", "Welcome to Widows Bay"]
|
||||||
# 'added' is still available opt-in (newest first)
|
# 'added' is still available opt-in (newest first)
|
||||||
added = [it["title"] for it in db.query_watchlist("show", sort="added")["items"]]
|
added = [it["title"].strip() for it in db.query_watchlist("show", sort="added")["items"]]
|
||||||
assert added[0] == "Andor" # most recently added
|
assert added[0] == "Holy Marvels with Dennis Quaid" # most recently added
|
||||||
|
|
||||||
|
|
||||||
# ── wishlist (movies + episodes; show/season are bulk ops over episodes) ──────
|
# ── wishlist (movies + episodes; show/season are bulk ops over episodes) ──────
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue