mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 03:51:08 +00:00
chore: sort editions with series number before edition rank
This commit is contained in:
parent
23e04c2e62
commit
0628ccad41
1 changed files with 7 additions and 7 deletions
|
@ -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 = {
|
||||||
|
|
Loading…
Reference in a new issue