Don't show ratings below user statuses

This commit is contained in:
Mouse Reeve 2021-05-18 11:09:19 -07:00
parent ab69abb8f0
commit 07d59c8c09
2 changed files with 8 additions and 3 deletions

View file

@ -195,7 +195,7 @@
{% endif %}
<div class="block" id="reviews">
{% if request.user.is_authenticated %}
{% if user_statuses.review_count or user_statuses.comment_count or user_stuatses.quotation_count %}
{% if user_statuses.review_count or user_statuses.comment_count or user_statuses.quotation_count %}
<nav class="tabs">
<ul>
{% url 'book' book.id as tab_url %}
@ -238,6 +238,7 @@
</div>
{% endfor %}
{% if ratings %}
<div class="block is-flex is-flex-wrap-wrap">
{% for rating in ratings %}
{% with user=rating.user %}
@ -265,6 +266,7 @@
{% endwith %}
{% endfor %}
</div>
{% endif %}
<div class="block">
{% include 'snippets/pagination.html' with page=statuses path=request.path anchor="#reviews" %}
</div>

View file

@ -30,6 +30,7 @@ class Book(View):
def get(self, request, book_id, user_statuses=False):
"""info about a book"""
user_statuses = user_statuses if request.user.is_authenticated else False
try:
book = models.Book.objects.select_subclasses().get(id=book_id)
except models.Book.DoesNotExist:
@ -51,7 +52,7 @@ class Book(View):
)
# the reviews to show
if user_statuses and request.user.is_authenticated:
if user_statuses:
if user_statuses == "review":
queryset = book.review_set
elif user_statuses == "comment":
@ -67,7 +68,9 @@ class Book(View):
"book": book,
"statuses": paginated.get_page(request.GET.get("page")),
"review_count": reviews.count(),
"ratings": reviews.filter(Q(content__isnull=True) | Q(content="")),
"ratings": reviews.filter(Q(content__isnull=True) | Q(content=""))
if not user_statuses
else None,
"rating": reviews.aggregate(Avg("rating"))["rating__avg"],
"lists": privacy_filter(
request.user, book.list_set.filter(listitem__approved=True)