Merge pull request #820 from mouse-reeve/paginate-editions

Paginates editions page
This commit is contained in:
Mouse Reeve 2021-03-29 12:31:22 -07:00 committed by GitHub
commit f07f822d36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -33,4 +33,8 @@
</div>
{% endfor %}
</div>
<div>
{% include 'snippets/pagination.html' with page=editions path=request.path %}
</div>
{% endblock %}

View file

@ -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(