Filter pending books from list display
This commit is contained in:
parent
482c464979
commit
8fb08e09fd
|
@ -42,7 +42,9 @@ class List(OrderedCollectionMixin, BookWyrmModel):
|
||||||
@property
|
@property
|
||||||
def collection_queryset(self):
|
def collection_queryset(self):
|
||||||
''' list of books for this shelf, overrides OrderedCollectionMixin '''
|
''' 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:
|
class Meta:
|
||||||
''' default sorting '''
|
''' default sorting '''
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
''' book list views'''
|
''' book list views'''
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.paginator import Paginator
|
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.http import HttpResponseNotFound, HttpResponseBadRequest
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
@ -27,9 +27,13 @@ class Lists(View):
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
user = request.user if request.user.is_authenticated else None
|
user = request.user if request.user.is_authenticated else None
|
||||||
|
# hide lists with no approved books
|
||||||
lists = models.List.objects.filter(
|
lists = models.List.objects.filter(
|
||||||
~Q(user=user),
|
~Q(user=user),
|
||||||
books__isnull=False,
|
).annotate(
|
||||||
|
item_count=Count('listitem', filter=Q(listitem__approved=True))
|
||||||
|
).filter(
|
||||||
|
item_count__gt=0
|
||||||
).distinct().all()
|
).distinct().all()
|
||||||
lists = privacy_filter(request.user, lists, ['public', 'followers'])
|
lists = privacy_filter(request.user, lists, ['public', 'followers'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue