fixes book reviews queryset aggregators

This commit is contained in:
Mouse Reeve 2021-02-24 12:24:19 -08:00
parent 779581c6f4
commit a5ee535ab6
3 changed files with 16 additions and 15 deletions

View file

@ -122,7 +122,8 @@ class ViewsHelpers(TestCase):
self.assertEqual(statuses[1], public_status)
self.assertEqual(statuses[0], rat_public)
statuses = views.helpers.get_activity_feed(self.local_user, 'direct')
statuses = views.helpers.get_activity_feed(
self.local_user, privacy=['direct'])
self.assertEqual(len(statuses), 1)
self.assertEqual(statuses[0], direct_status)

View file

@ -45,13 +45,9 @@ class Book(View):
if not work:
return HttpResponseNotFound()
reviews = models.Review.objects.filter(
book__in=work.editions.all(),
)
# all reviews for the book
reviews = get_activity_feed(
request.user, queryset=reviews
)
reviews = models.Review.objects.filter(book__in=work.editions.all())
reviews = get_activity_feed(request.user, queryset=reviews)
# the reviews to show
paginated = Paginator(reviews.exclude(

View file

@ -117,7 +117,7 @@ def get_activity_feed(
user, privacy=None, local_only=False, following_only=False,
queryset=None):
''' get a filtered queryset of statuses '''
if not queryset:
if queryset is None:
queryset = models.Status.objects.select_subclasses()
# exclude deleted
@ -137,13 +137,17 @@ def get_activity_feed(
generatednote__isnull=True,
)
else:
queryset = queryset.exclude(
review__isnull=True,
comment__isnull=True,
quotation__isnull=True,
generatednote__isnull=True,
privacy='direct'
)
try:
queryset = queryset.exclude(
review__isnull=True,
comment__isnull=True,
quotation__isnull=True,
generatednote__isnull=True,
privacy='direct'
)
except FieldError:
# if we're looking at a subtype of Status (like Review)
pass
# filter for only local status
if local_only: