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> </div>
{% endfor %} {% endfor %}
</div> </div>
<div>
{% include 'snippets/pagination.html' with page=editions path=request.path %}
</div>
{% endblock %} {% endblock %}

View file

@ -250,6 +250,11 @@ class Editions(View):
""" list of editions of a book """ """ list of editions of a book """
work = get_object_or_404(models.Work, id=book_id) 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): if is_api_request(request):
return ActivitypubResponse(work.to_edition_list(**request.GET)) return ActivitypubResponse(work.to_edition_list(**request.GET))
filters = {} filters = {}
@ -262,8 +267,9 @@ class Editions(View):
editions = work.editions.order_by("-edition_rank").all() editions = work.editions.order_by("-edition_rank").all()
languages = set(sum([e.languages for e in editions], [])) languages = set(sum([e.languages for e in editions], []))
paginated = Paginator(editions.filter(**filters).all(), PAGE_LENGTH)
data = { data = {
"editions": editions.filter(**filters).all(), "editions": paginated.page(page),
"work": work, "work": work,
"languages": languages, "languages": languages,
"formats": set( "formats": set(