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[1], public_status)
self.assertEqual(statuses[0], rat_public) 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(len(statuses), 1)
self.assertEqual(statuses[0], direct_status) self.assertEqual(statuses[0], direct_status)

View file

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

View file

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