From 04ca6de96863c03830506efe356d807c9e152fe9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 29 Mar 2021 12:13:05 -0700 Subject: [PATCH] Paginates editions page --- bookwyrm/templates/book/editions.html | 4 ++++ bookwyrm/views/books.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/book/editions.html b/bookwyrm/templates/book/editions.html index 7290cce93..91259465e 100644 --- a/bookwyrm/templates/book/editions.html +++ b/bookwyrm/templates/book/editions.html @@ -33,4 +33,8 @@ {% endfor %} + +
+ {% include 'snippets/pagination.html' with page=editions path=request.path %} +
{% endblock %} diff --git a/bookwyrm/views/books.py b/bookwyrm/views/books.py index 895c7ec9f..632cb2ad9 100644 --- a/bookwyrm/views/books.py +++ b/bookwyrm/views/books.py @@ -250,6 +250,11 @@ class Editions(View): """ list of editions of a book """ work = get_object_or_404(models.Work, id=book_id) + try: + page = int(request.GET.get("page", 1)) + except ValueError: + page = 1 + if is_api_request(request): return ActivitypubResponse(work.to_edition_list(**request.GET)) filters = {} @@ -262,8 +267,9 @@ class Editions(View): editions = work.editions.order_by("-edition_rank").all() languages = set(sum([e.languages for e in editions], [])) + paginated = Paginator(editions.filter(**filters).all(), PAGE_LENGTH) data = { - "editions": editions.filter(**filters).all(), + "editions": paginated.page(page), "work": work, "languages": languages, "formats": set(