mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-06-05 15:28:52 +00:00
fix: books can have non-decimal series numbers
This commit is contained in:
parent
b20b52af7f
commit
d1f85e4317
1 changed files with 10 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
""" books belonging to the same series """
|
""" books belonging to the same series """
|
||||||
|
from sys import float_info
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
@ -7,6 +8,14 @@ from bookwyrm.views.helpers import is_api_request
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
|
||||||
|
|
||||||
|
def sort_by_series(book):
|
||||||
|
"""sort books using their series number"""
|
||||||
|
try:
|
||||||
|
return float(book.series_number)
|
||||||
|
except ValueError:
|
||||||
|
return float_info.max
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
class BookSeriesBy(View):
|
class BookSeriesBy(View):
|
||||||
"""book series by author"""
|
"""book series by author"""
|
||||||
|
@ -44,7 +53,7 @@ class BookSeriesBy(View):
|
||||||
unsortable_books.append(result)
|
unsortable_books.append(result)
|
||||||
|
|
||||||
list_results = (
|
list_results = (
|
||||||
sorted(numbered_books, key=lambda book: float(book.series_number))
|
sorted(numbered_books, key=sort_by_series)
|
||||||
+ sorted(
|
+ sorted(
|
||||||
dated_books,
|
dated_books,
|
||||||
key=lambda book: book.first_published_date
|
key=lambda book: book.first_published_date
|
||||||
|
|
Loading…
Reference in a new issue