Merge pull request #600 from mouse-reeve/list-fixes

Filter pending books from list display
This commit is contained in:
Mouse Reeve 2021-02-09 12:53:00 -08:00 committed by GitHub
commit 5aba7d203d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -42,7 +42,9 @@ class List(OrderedCollectionMixin, BookWyrmModel):
@property
def collection_queryset(self):
''' list of books for this shelf, overrides OrderedCollectionMixin '''
return self.books.all().order_by('listitem')
return self.books.filter(
listitem__approved=True
).all().order_by('listitem')
class Meta:
''' default sorting '''

View file

@ -1,7 +1,7 @@
''' 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.db.models import Count, Q
from django.http import HttpResponseNotFound, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
@ -27,9 +27,13 @@ class Lists(View):
page = 1
user = request.user if request.user.is_authenticated else None
# hide lists with no approved books
lists = models.List.objects.filter(
~Q(user=user),
books__isnull=False,
).annotate(
item_count=Count('listitem', filter=Q(listitem__approved=True))
).filter(
item_count__gt=0
).distinct().all()
lists = privacy_filter(request.user, lists, ['public', 'followers'])