forked from mirrors/bookwyrm
Merge pull request #1261 from bookwyrm-social/list-display
Improves cross-edition display for lists
This commit is contained in:
commit
d7a79573c4
2 changed files with 9 additions and 4 deletions
|
@ -12,7 +12,7 @@ register = template.Library()
|
||||||
def get_rating(book, user):
|
def get_rating(book, user):
|
||||||
"""get the overall rating of a book"""
|
"""get the overall rating of a book"""
|
||||||
queryset = views.helpers.privacy_filter(
|
queryset = views.helpers.privacy_filter(
|
||||||
user, models.Review.objects.filter(book=book)
|
user, models.Review.objects.filter(book__in=book.parent_work.editions.all())
|
||||||
)
|
)
|
||||||
return queryset.aggregate(Avg("rating"))["rating__avg"]
|
return queryset.aggregate(Avg("rating"))["rating__avg"]
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,13 @@ class Book(View):
|
||||||
queryset = queryset.select_related("user")
|
queryset = queryset.select_related("user")
|
||||||
paginated = Paginator(queryset, PAGE_LENGTH)
|
paginated = Paginator(queryset, PAGE_LENGTH)
|
||||||
|
|
||||||
|
lists = privacy_filter(
|
||||||
|
request.user,
|
||||||
|
models.List.objects.filter(
|
||||||
|
listitem__approved=True,
|
||||||
|
listitem__book__in=book.parent_work.editions.all(),
|
||||||
|
),
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
"book": book,
|
"book": book,
|
||||||
"statuses": paginated.get_page(request.GET.get("page")),
|
"statuses": paginated.get_page(request.GET.get("page")),
|
||||||
|
@ -75,9 +82,7 @@ class Book(View):
|
||||||
if not user_statuses
|
if not user_statuses
|
||||||
else None,
|
else None,
|
||||||
"rating": reviews.aggregate(Avg("rating"))["rating__avg"],
|
"rating": reviews.aggregate(Avg("rating"))["rating__avg"],
|
||||||
"lists": privacy_filter(
|
"lists": lists,
|
||||||
request.user, book.list_set.filter(listitem__approved=True)
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
|
|
Loading…
Reference in a new issue