chore: sort editions with series number before edition rank

This commit is contained in:
Dustin Steiner 2023-01-29 11:43:30 +00:00
parent 23e04c2e62
commit 0628ccad41
No known key found for this signature in database
GPG key ID: 918D51522D8CB8F2

View file

@ -22,16 +22,16 @@ class BookSeriesBy(View):
results = models.Edition.objects.filter(authors=author, series=series_name) results = models.Edition.objects.filter(authors=author, series=series_name)
# when there are multiple editions of the same work, pick the closest # when there are multiple editions of the same work, pick the one with a series number or closest
editions_of_work = results.values_list("parent_work__id", flat=True).distinct() work_ids = results.values_list("parent_work__id", flat=True).distinct()
# filter out multiple editions of the same work # filter out multiple editions of the same work
numbered_books = [] numbered_books = []
dated_books = [] dated_books = []
unsortable_books = [] unsortable_books = []
for work_id in set(editions_of_work): for work_id in set(work_ids):
result = ( result = (
results.filter(parent_work=work_id).order_by("-edition_rank").first() results.filter(parent_work=work_id).order_by("series_number", "-edition_rank").first()
) )
if result.series_number: if result.series_number:
numbered_books.append(result) numbered_books.append(result)
@ -48,7 +48,7 @@ class BookSeriesBy(View):
if book.first_published_date if book.first_published_date
else book.published_date, else book.published_date,
) )
+ sorted(unsortable_books, key=lambda book: book.sort_title) + sorted(unsortable_books, key=lambda book: book.sort_title if book.sort_title else book.title)
) )
data = { data = {