From 7680ba4bb07c36ecb03aa86c8f16a88024ae3e8c Mon Sep 17 00:00:00 2001 From: Tuan-Dung Bui Date: Wed, 12 Apr 2023 00:09:00 +0700 Subject: [PATCH] fix queryset --- judge/comments.py | 5 ++--- judge/views/comment.py | 6 ++++-- templates/comments/content-list.html | 29 +++++++++++++++------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/judge/comments.py b/judge/comments.py index 09171b0..92fb153 100644 --- a/judge/comments.py +++ b/judge/comments.py @@ -164,8 +164,8 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View): queryset = self.object.comments context["replies"] = len(queryset.filter(parent=None)) queryset = ( - queryset.filter(parent=None)[:10].select_related("author__user") - .filter(hidden=False) + queryset.filter(parent=None, hidden=False)[:10] + .select_related("author__user") .defer("author__about") .annotate(revisions=Count("versions")) .annotate(count_replies=Count("replies")) @@ -186,7 +186,6 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View): ).exists() ) context["comment_list"] = queryset - # context["comment_count"] = len(queryset) context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD context["comment_root_id"] = 0 context["offset"] = 10 diff --git a/judge/views/comment.py b/judge/views/comment.py index bba7d38..73b4fca 100644 --- a/judge/views/comment.py +++ b/judge/views/comment.py @@ -137,9 +137,11 @@ def get_comment(request, limit=10): queryset = page_obj.comments replies = len(queryset.filter(parent=comment_obj)) queryset = ( - queryset.filter(parent=comment_obj)[offset:offset+limit].select_related("author__user") + queryset.filter(parent=comment_obj, hidden=False)[offset:offset+limit] + .select_related("author__user") .defer("author__about") - .annotate(revisions=Count("versions")).annotate(count_replies=Count("replies")) + .annotate(revisions=Count("versions")) + .annotate(count_replies=Count("replies")) ) if request.user.is_authenticated: profile = request.profile diff --git a/templates/comments/content-list.html b/templates/comments/content-list.html index 04507b0..b60deec 100644 --- a/templates/comments/content-list.html +++ b/templates/comments/content-list.html @@ -23,16 +23,16 @@ title="{{ _('Please login to vote') }}" class="downvote-link fa fa-chevron-down fa-fw"> {% endif %} - {% with author=node.author, user=node.author.user %} - - - - {% endwith %}
- {{ link_user(node.author) }}  - {{ relative_time(node.time, abs=_('commented on {time}'), rel=_('commented {time}')) }} + {% with author=node.author, user=node.author.user %} + + + + {% endwith %} + {{ link_user(node.author) }},  + {{ relative_time(node.time, abs=_('{time}'), rel=_('{time}')) }} {% if node.revisions > 1 %} @@ -101,21 +101,24 @@ {% if node.revisions == 1 %} - {% set real_replies = node.count_replies - node.revisions + 1 %} + {% set real_replies = node.count_replies - node.revisions + 1 %} {% else %} - {% set real_replies = node.count_replies - node.revisions + 2 %} + {% set real_replies = node.count_replies - node.revisions + 2 %} {% endif %} {% if real_replies > 1 %} - {{ real_replies }} {{ _(' Replies ') }} + {{ real_replies }} {{ + _(' Replies ') }} {% elif real_replies %} - {{ real_replies }} {{ _(' Reply ') }} - {% endif %} + {{ real_replies }} {{ + _(' Reply ') }} + {% endif %}
{% endfor %} {% if replies - offset > 0 %} - {{ replies - offset }} Replies More + + {{ replies - offset }} Replies More {% endif %} \ No newline at end of file