Merge pull request #1215 from bookwyrm-social/user-status-counts

Hide deleted status counts from book page
This commit is contained in:
Mouse Reeve 2021-07-07 11:55:18 -06:00 committed by GitHub
commit 1d90ccdcaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View file

@ -209,24 +209,24 @@
<ul> <ul>
{% url 'book' book.id as tab_url %} {% url 'book' book.id as tab_url %}
<li {% if tab_url == request.path %}class="is-active"{% endif %}> <li {% if tab_url == request.path %}class="is-active"{% endif %}>
<a href="{{ tab_url }}">{% trans "Reviews" %} ({{ review_count }})</a> <a href="{{ tab_url }}#reviews">{% trans "Reviews" %} ({{ review_count }})</a>
</li> </li>
{% if user_statuses.review_count %} {% if user_statuses.review_count %}
{% url 'book-user-statuses' book.id 'review' as tab_url %} {% url 'book-user-statuses' book.id 'review' as tab_url %}
<li {% if tab_url == request.path %}class="is-active"{% endif %}> <li {% if tab_url == request.path %}class="is-active"{% endif %}>
<a href="{{ tab_url }}">{% trans "Your reviews" %} ({{ user_statuses.review_count }})</a> <a href="{{ tab_url }}#reviews">{% trans "Your reviews" %} ({{ user_statuses.review_count }})</a>
</li> </li>
{% endif %} {% endif %}
{% if user_statuses.comment_count %} {% if user_statuses.comment_count %}
{% url 'book-user-statuses' book.id 'comment' as tab_url %} {% url 'book-user-statuses' book.id 'comment' as tab_url %}
<li {% if tab_url == request.path %}class="is-active"{% endif %}> <li {% if tab_url == request.path %}class="is-active"{% endif %}>
<a href="{{ tab_url }}">{% trans "Your comments" %} ({{ user_statuses.comment_count }})</a> <a href="{{ tab_url }}#reviews">{% trans "Your comments" %} ({{ user_statuses.comment_count }})</a>
</li> </li>
{% endif %} {% endif %}
{% if user_statuses.quotation_count %} {% if user_statuses.quotation_count %}
{% url 'book-user-statuses' book.id 'quote' as tab_url %} {% url 'book-user-statuses' book.id 'quote' as tab_url %}
<li {% if tab_url == request.path %}class="is-active"{% endif %}> <li {% if tab_url == request.path %}class="is-active"{% endif %}>
<a href="{{ tab_url }}">{% trans "Your quotes" %} ({{ user_statuses.quotation_count }})</a> <a href="{{ tab_url }}#reviews">{% trans "Your quotes" %} ({{ user_statuses.quotation_count }})</a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>

View file

@ -59,7 +59,7 @@ class Book(View):
queryset = book.comment_set queryset = book.comment_set
else: else:
queryset = book.quotation_set queryset = book.quotation_set
queryset = queryset.filter(user=request.user) queryset = queryset.filter(user=request.user, deleted=False)
else: else:
queryset = reviews.exclude(Q(content__isnull=True) | Q(content="")) queryset = reviews.exclude(Q(content__isnull=True) | Q(content=""))
queryset = queryset.select_related("user") queryset = queryset.select_related("user")
@ -102,10 +102,11 @@ class Book(View):
book__parent_work=book.parent_work, book__parent_work=book.parent_work,
).select_related("shelf", "book") ).select_related("shelf", "book")
filters = {"user": request.user, "deleted": False}
data["user_statuses"] = { data["user_statuses"] = {
"review_count": book.review_set.filter(user=request.user).count(), "review_count": book.review_set.filter(**filters).count(),
"comment_count": book.comment_set.filter(user=request.user).count(), "comment_count": book.comment_set.filter(**filters).count(),
"quotation_count": book.quotation_set.filter(user=request.user).count(), "quotation_count": book.quotation_set.filter(**filters).count(),
} }
return TemplateResponse(request, "book/book.html", data) return TemplateResponse(request, "book/book.html", data)