fix queryset
This commit is contained in:
parent
e02675279d
commit
7680ba4bb0
3 changed files with 22 additions and 18 deletions
|
@ -164,8 +164,8 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||||
queryset = self.object.comments
|
queryset = self.object.comments
|
||||||
context["replies"] = len(queryset.filter(parent=None))
|
context["replies"] = len(queryset.filter(parent=None))
|
||||||
queryset = (
|
queryset = (
|
||||||
queryset.filter(parent=None)[:10].select_related("author__user")
|
queryset.filter(parent=None, hidden=False)[:10]
|
||||||
.filter(hidden=False)
|
.select_related("author__user")
|
||||||
.defer("author__about")
|
.defer("author__about")
|
||||||
.annotate(revisions=Count("versions"))
|
.annotate(revisions=Count("versions"))
|
||||||
.annotate(count_replies=Count("replies"))
|
.annotate(count_replies=Count("replies"))
|
||||||
|
@ -186,7 +186,6 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
|
||||||
).exists()
|
).exists()
|
||||||
)
|
)
|
||||||
context["comment_list"] = queryset
|
context["comment_list"] = queryset
|
||||||
# context["comment_count"] = len(queryset)
|
|
||||||
context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
|
context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
|
||||||
context["comment_root_id"] = 0
|
context["comment_root_id"] = 0
|
||||||
context["offset"] = 10
|
context["offset"] = 10
|
||||||
|
|
|
@ -137,9 +137,11 @@ def get_comment(request, limit=10):
|
||||||
queryset = page_obj.comments
|
queryset = page_obj.comments
|
||||||
replies = len(queryset.filter(parent=comment_obj))
|
replies = len(queryset.filter(parent=comment_obj))
|
||||||
queryset = (
|
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")
|
.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:
|
if request.user.is_authenticated:
|
||||||
profile = request.profile
|
profile = request.profile
|
||||||
|
|
|
@ -23,16 +23,16 @@
|
||||||
title="{{ _('Please login to vote') }}" class="downvote-link fa fa-chevron-down fa-fw"></a>
|
title="{{ _('Please login to vote') }}" class="downvote-link fa fa-chevron-down fa-fw"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% with author=node.author, user=node.author.user %}
|
|
||||||
<a href="{{ url('user_page', user.username) }}" class="user">
|
|
||||||
<img src="{{ gravatar(author, 135) }}" class="gravatar">
|
|
||||||
</a>
|
|
||||||
{% endwith %}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="detail">
|
<div class="detail">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{ link_user(node.author) }}
|
{% with author=node.author, user=node.author.user %}
|
||||||
{{ relative_time(node.time, abs=_('commented on {time}'), rel=_('commented {time}')) }}
|
<a href="{{ url('user_page', user.username) }}" class="user comment-img">
|
||||||
|
<img src="{{ gravatar(author, 135) }}" class="gravatar">
|
||||||
|
</a>
|
||||||
|
{% endwith %}
|
||||||
|
{{ link_user(node.author) }},
|
||||||
|
{{ relative_time(node.time, abs=_('{time}'), rel=_('{time}')) }}
|
||||||
<span class="comment-spacer"></span>
|
<span class="comment-spacer"></span>
|
||||||
<span class="comment-operation">
|
<span class="comment-operation">
|
||||||
{% if node.revisions > 1 %}
|
{% if node.revisions > 1 %}
|
||||||
|
@ -101,15 +101,17 @@
|
||||||
<!-- {{ node.count_replies }}
|
<!-- {{ node.count_replies }}
|
||||||
{{node.revisions - 1}} -->
|
{{node.revisions - 1}} -->
|
||||||
{% if node.revisions == 1 %}
|
{% if node.revisions == 1 %}
|
||||||
{% set real_replies = node.count_replies - node.revisions + 1 %}
|
{% set real_replies = node.count_replies - node.revisions + 1 %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set real_replies = node.count_replies - node.revisions + 2 %}
|
{% set real_replies = node.count_replies - node.revisions + 2 %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if real_replies > 1 %}
|
{% if real_replies > 1 %}
|
||||||
<a href="javascript:comment_reply({{ node.id }}, {{ object.id }})" class="show_more_reply"> {{ real_replies }} {{ _(' Replies ') }} </a>
|
<a href="javascript:comment_reply({{ node.id }}, {{ object.id }})" class="show_more_reply"> {{ real_replies }} {{
|
||||||
|
_(' Replies ') }} </a>
|
||||||
{% elif real_replies %}
|
{% elif real_replies %}
|
||||||
<a href="javascript:comment_reply({{ node.id }}, {{ object.id }})" class="show_more_reply"> {{ real_replies }} {{ _(' Reply ') }} </a>
|
<a href="javascript:comment_reply({{ node.id }}, {{ object.id }})" class="show_more_reply"> {{ real_replies }} {{
|
||||||
|
_(' Reply ') }} </a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
<ul id="comment-{{ node.id }}-reply" class="reply-comment" hidden></ul>
|
<ul id="comment-{{ node.id }}-reply" class="reply-comment" hidden></ul>
|
||||||
|
@ -117,5 +119,6 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if replies - offset > 0 %}
|
{% if replies - offset > 0 %}
|
||||||
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ object.id }}, {{ offset }} )" class="show_more_comment"> {{ replies - offset }} Replies More</a>
|
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ object.id }}, {{ offset }} )" class="show_more_comment">
|
||||||
|
{{ replies - offset }} Replies More</a>
|
||||||
{% endif %}
|
{% endif %}
|
Loading…
Add table
Add a link
Reference in a new issue