From d7c32cc3143362cb8d3ff1d7e0ad190c55e0c9ca Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 31 Jan 2021 17:34:06 -0800 Subject: [PATCH] Paginates lists view --- bookwyrm/models/list.py | 4 ++++ bookwyrm/templates/lists/lists.html | 15 +++++++++++---- bookwyrm/views/list.py | 13 +++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 96bf0b7a..6ade16de 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -46,6 +46,10 @@ class List(OrderedCollectionMixin, BookWyrmModel): ''' list of books for this shelf, overrides OrderedCollectionMixin ''' return self.books.all().order_by('listitem') + class Meta: + ''' default sorting ''' + ordering = ('-updated_date',) + class ListItem(ActivitypubMixin, BookWyrmModel): ''' ok ''' diff --git a/bookwyrm/templates/lists/lists.html b/bookwyrm/templates/lists/lists.html index b016b9f1..36250331 100644 --- a/bookwyrm/templates/lists/lists.html +++ b/bookwyrm/templates/lists/lists.html @@ -4,8 +4,7 @@

Lists

- -{% if request.user.is_authenticated %} +{% if request.user.is_authenticated and not lists.has_previous %}
@@ -27,18 +26,26 @@ {% if request.user.list_set.exists %} - {% include 'lists/list_items.html' with lists=request.user.list_set.all %} + {% include 'lists/list_items.html' with lists=request.user.list_set.all|slice:4 %} + {% endif %} + + {% if request.user.list_set.count > 4 %} + See all {{ request.user.list_set.count}} lists {% endif %}
{% endif %} -{% if lists.exists %} + +{% if lists %}

Recent Lists

{% if request.user.list_set.exists %} {% include 'lists/list_items.html' with lists=lists %} {% endif %}
+
+ {% include 'snippets/pagination.html' with page=lists path=path %} +
{% endif %} {% endblock %} diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 9ef2ae3b..01af2d19 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -1,5 +1,6 @@ ''' book list views''' from django.contrib.auth.decorators import login_required +from django.core.paginator import Paginator from django.db.models import Q from django.http import HttpResponseNotFound, HttpResponseBadRequest from django.shortcuts import get_object_or_404, redirect @@ -19,15 +20,23 @@ class Lists(View): ''' book list page ''' def get(self, request): ''' display a book list ''' + try: + page = int(request.GET.get('page', 1)) + except ValueError: + page = 1 + user = request.user if request.user.is_authenticated else None lists = models.List.objects.filter( ~Q(user=user), ).all() lists = privacy_filter(request.user, lists, ['public', 'followers']) + + paginated = Paginator(lists, 12) data = { 'title': 'Lists', - 'lists': lists, - 'list_form': forms.ListForm() + 'lists': paginated.page(page), + 'list_form': forms.ListForm(), + 'path': '/list', } return TemplateResponse(request, 'lists/lists.html', data)