From 3a7d4d8f0a5bae748a64766334b91b535c3f8746 Mon Sep 17 00:00:00 2001 From: Phuoc Anh Kha Le <76896393+anhkha2003@users.noreply.github.com> Date: Wed, 25 Oct 2023 02:19:05 -0500 Subject: [PATCH] Fix Comment bugs (#93) --- judge/comments.py | 8 +++++--- templates/comments/media-js.html | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/judge/comments.py b/judge/comments.py index dde97a0..98434cf 100644 --- a/judge/comments.py +++ b/judge/comments.py @@ -144,14 +144,16 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View): def get(self, request, *args, **kwargs): target_comment = None + self.object = self.get_object() if "comment-id" in request.GET: - comment_id = int(request.GET["comment-id"]) try: + comment_id = int(request.GET["comment-id"]) comment_obj = Comment.objects.get(id=comment_id) - except Comment.DoesNotExist: + except (Comment.DoesNotExist, ValueError): + raise Http404 + if comment_obj.linked_object != self.object: raise Http404 target_comment = comment_obj.get_root() - self.object = self.get_object() return self.render_to_response( self.get_context_data( object=self.object, diff --git a/templates/comments/media-js.html b/templates/comments/media-js.html index 862dbee..4c85ae4 100644 --- a/templates/comments/media-js.html +++ b/templates/comments/media-js.html @@ -145,6 +145,8 @@ $comment_loading.hide(); var $comment = $("#comment-" + id + "-children"); $comment.append(data); + MathJax.typeset($('#comments')[0]); + register_time($('.time-with-rel')); } }) } @@ -187,6 +189,7 @@ $comment.append(data); } MathJax.typeset($('#comments')[0]); + register_time($('.time-with-rel')); } }) }