Paginates editions page

This commit is contained in:
Mouse Reeve 2021-03-29 12:13:05 -07:00
parent 91b81de8a7
commit 04ca6de968
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(