mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-09 08:45:28 +00:00
style: run linter
This commit is contained in:
parent
35d30a41f3
commit
cd13e6f523
2 changed files with 47 additions and 42 deletions
|
@ -610,7 +610,11 @@ urlpatterns = [
|
||||||
# books
|
# books
|
||||||
re_path(rf"{BOOK_PATH}(.json)?/?$", views.Book.as_view(), name="book"),
|
re_path(rf"{BOOK_PATH}(.json)?/?$", views.Book.as_view(), name="book"),
|
||||||
re_path(rf"{BOOK_PATH}{regex.SLUG}/?$", views.Book.as_view(), name="book"),
|
re_path(rf"{BOOK_PATH}{regex.SLUG}/?$", views.Book.as_view(), name="book"),
|
||||||
re_path(r"^series/by/(?P<author_id>\d+)/?$", views.BookSeriesBy.as_view(), name="book-series-by"),
|
re_path(
|
||||||
|
r"^series/by/(?P<author_id>\d+)/?$",
|
||||||
|
views.BookSeriesBy.as_view(),
|
||||||
|
name="book-series-by",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
rf"{BOOK_PATH}/(?P<user_statuses>review|comment|quote)/?$",
|
rf"{BOOK_PATH}/(?P<user_statuses>review|comment|quote)/?$",
|
||||||
views.Book.as_view(),
|
views.Book.as_view(),
|
||||||
|
|
|
@ -10,49 +10,50 @@ from bookwyrm.settings import PAGE_LENGTH
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
class BookSeriesBy(View):
|
class BookSeriesBy(View):
|
||||||
def get(self, request, author_id, **kwargs):
|
def get(self, request, author_id, **kwargs):
|
||||||
"""lists all books in a series"""
|
"""lists all books in a series"""
|
||||||
series_name = request.GET.get("series_name")
|
series_name = request.GET.get("series_name")
|
||||||
|
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
author = get_object_or_404(models.Author, id=author_id)
|
author = get_object_or_404(models.Author, id=author_id)
|
||||||
|
|
||||||
results = (
|
results = models.Edition.objects.filter(authors=author, series=series_name)
|
||||||
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 closest
|
||||||
editions_of_work = results.values_list("parent_work__id", flat=True).distinct()
|
editions_of_work = 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(editions_of_work):
|
||||||
result = (
|
result = (
|
||||||
results.filter(parent_work=work_id)
|
results.filter(parent_work=work_id).order_by("-edition_rank").first()
|
||||||
.order_by("-edition_rank")
|
)
|
||||||
.first()
|
if result.series_number:
|
||||||
)
|
numbered_books.append(result)
|
||||||
if result.series_number:
|
elif result.first_published_date or result.published_date:
|
||||||
numbered_books.append(result)
|
dated_books.append(result)
|
||||||
elif result.first_published_date or result.published_date:
|
else:
|
||||||
dated_books.append(result)
|
unsortable_books.append(result)
|
||||||
else:
|
|
||||||
unsortable_books.append(result)
|
|
||||||
|
|
||||||
list_results = (
|
list_results = (
|
||||||
sorted(numbered_books, key=lambda book: book.series_number) +
|
sorted(numbered_books, key=lambda book: book.series_number)
|
||||||
sorted(dated_books, key=lambda book: book.first_published_date if book.first_published_date else book.published_date) +
|
+ sorted(
|
||||||
sorted(unsortable_books, key=lambda book: book.sort_title)
|
dated_books,
|
||||||
)
|
key=lambda book: book.first_published_date
|
||||||
|
if book.first_published_date
|
||||||
|
else book.published_date,
|
||||||
|
)
|
||||||
|
+ sorted(unsortable_books, key=lambda book: book.sort_title)
|
||||||
|
)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"series_name": series_name,
|
"series_name": series_name,
|
||||||
"author": author,
|
"author": author,
|
||||||
"books": list_results,
|
"books": list_results,
|
||||||
}
|
}
|
||||||
|
|
||||||
return TemplateResponse(request, "book/series.html", data)
|
return TemplateResponse(request, "book/series.html", data)
|
||||||
|
|
Loading…
Reference in a new issue