1
0
Fork 0

chore: formatting

This commit is contained in:
Dustin Steiner 2023-01-30 14:45:30 +00:00
parent 59a8098517
commit e0505722e1
No known key found for this signature in database
GPG key ID: 918D51522D8CB8F2

View file

@ -21,17 +21,19 @@ class BookSeriesBy(View):
author = get_object_or_404(models.Author, id=author_id) author = get_object_or_404(models.Author, id=author_id)
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 one with a series number or closest # when there are multiple editions of the same work, pick the one with a series number or closest
work_ids = 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(work_ids): for work_id in set(work_ids):
result = ( result = (
results.filter(parent_work=work_id).order_by("series_number", "-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 +50,10 @@ 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 if book.sort_title else book.title) + sorted(
unsortable_books,
key=lambda book: book.sort_title if book.sort_title else book.title,
)
) )
data = { data = {