try comment show with link
This commit is contained in:
parent
49a186f72f
commit
d1f9c12c2d
8 changed files with 264 additions and 60 deletions
|
@ -116,14 +116,12 @@ def downvote_comment(request):
|
|||
def get_comments(request, limit=10):
|
||||
try:
|
||||
comment_id = int(request.GET["id"])
|
||||
page_id = int(request.GET["page"])
|
||||
parrent_none = int(request.GET["parrent_none"])
|
||||
except ValueError:
|
||||
return HttpResponseBadRequest()
|
||||
else:
|
||||
if comment_id and not Comment.objects.filter(id=comment_id).exists():
|
||||
raise Http404()
|
||||
if not BlogPost.objects.filter(id=page_id).exists():
|
||||
raise Http404()
|
||||
offset = 0
|
||||
if "offset" in request.GET:
|
||||
offset = int(request.GET["offset"])
|
||||
|
@ -133,13 +131,14 @@ def get_comments(request, limit=10):
|
|||
comment_root_id = comment_obj.id
|
||||
else:
|
||||
comment_obj = None
|
||||
page_obj = BlogPost.objects.get(pk=page_id)
|
||||
queryset = page_obj.comments
|
||||
queryset = queryset.filter(parent=comment_obj, hidden=False)
|
||||
queryset = comment_obj.linked_object.comments
|
||||
if parrent_none:
|
||||
queryset = queryset.filter(parent=None, hidden=False)
|
||||
else:
|
||||
queryset = queryset.filter(parent=comment_obj, hidden=False)
|
||||
comment_count = len(queryset)
|
||||
queryset = (
|
||||
queryset
|
||||
.select_related("author__user")
|
||||
queryset.select_related("author__user")
|
||||
.defer("author__about")
|
||||
.annotate(
|
||||
count_replies=Count("replies", distinct=True),
|
||||
|
@ -153,7 +152,7 @@ def get_comments(request, limit=10):
|
|||
"votes", condition=Q(votes__voter_id=profile.id)
|
||||
),
|
||||
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
|
||||
|
||||
|
||||
comment_html = loader.render_to_string(
|
||||
"comments/content-list.html",
|
||||
{
|
||||
|
@ -162,13 +161,13 @@ def get_comments(request, limit=10):
|
|||
"comment_list": queryset,
|
||||
"vote_hide_threshold" : settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD,
|
||||
"perms": PermWrapper(request.user),
|
||||
"object": page_obj,
|
||||
"offset": offset + min(len(queryset), limit),
|
||||
"limit": limit,
|
||||
"comment_count": comment_count
|
||||
"comment_count": comment_count,
|
||||
"comment_parrent_none": parrent_none,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
return HttpResponse(comment_html)
|
||||
|
||||
def get_show_more(request):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue