mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-20 23:26:42 +00:00
fixes book reviews queryset aggregators
This commit is contained in:
parent
779581c6f4
commit
a5ee535ab6
3 changed files with 16 additions and 15 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue