Drop comment page

This commit is contained in:
cuom1999 2023-02-20 17:52:28 -06:00
parent 799ff5f8f8
commit f9207b811b
6 changed files with 25 additions and 56 deletions

View file

@ -98,7 +98,6 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
@method_decorator(login_required)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
page = self.get_comment_page()
if self.is_comment_locked():
return HttpResponseForbidden()
@ -116,7 +115,6 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
if form.is_valid():
comment = form.save(commit=False)
comment.author = request.profile
comment.page = page
comment.linked_object = self.object
with LockModel(

View file

@ -0,0 +1,24 @@
# Generated by Django 3.2.18 on 2023-02-20 23:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("judge", "0152_migrate_comments"),
]
operations = [
migrations.RemoveField(
model_name="comment",
name="page",
),
migrations.AlterField(
model_name="commentlock",
name="page",
field=models.CharField(
db_index=True, max_length=30, verbose_name="associated page"
),
),
]

View file

@ -24,10 +24,6 @@ from judge.utils.cachedict import CacheDict
__all__ = ["Comment", "CommentLock", "CommentVote", "Notification"]
comment_validator = RegexValidator(
r"^[pcs]:[a-z0-9]+$|^b:\d+$", _(r"Page code must be ^[pcs]:[a-z0-9]+$|^b:\d+$")
)
class VersionRelation(GenericRelation):
def __init__(self):
@ -49,12 +45,6 @@ class Comment(MPTTModel):
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
linked_object = GenericForeignKey("content_type", "object_id")
page = models.CharField(
max_length=30,
verbose_name=_("associated page"),
db_index=True,
validators=[comment_validator],
)
score = models.IntegerField(verbose_name=_("votes"), default=0)
body = models.TextField(verbose_name=_("body of comment"), max_length=8192)
hidden = models.BooleanField(verbose_name=_("hide the comment"), default=0)
@ -170,7 +160,6 @@ class CommentLock(models.Model):
max_length=30,
verbose_name=_("associated page"),
db_index=True,
validators=[comment_validator],
)
class Meta:

View file

@ -101,33 +101,12 @@ class PostList(HomeFeedView):
queryset = queryset.filter(filter)
return queryset
def get_feed_context(self, object_list):
post_comment_counts = {
int(page[2:]): count
for page, count in Comment.objects.filter(
page__in=["b:%d" % post.id for post in object_list], hidden=False
)
.values_list("page")
.annotate(count=Count("page"))
.order_by()
}
return {"post_comment_counts": post_comment_counts}
def get_context_data(self, **kwargs):
context = super(PostList, self).get_context_data(**kwargs)
context["title"] = (
self.title or _("Page %d of Posts") % context["page_obj"].number
)
context["page_type"] = "blog"
context["post_comment_counts"] = {
int(page[2:]): count
for page, count in Comment.objects.filter(
page__in=["b:%d" % post.id for post in context["posts"]], hidden=False
)
.values_list("page")
.annotate(count=Count("page"))
.order_by()
}
return context
def get_comment_page(self, post):

View file

@ -269,18 +269,6 @@ class OrganizationHome(OrganizationHomeView, FeedView):
def get_comment_page(self, post):
return "b:%s" % post.id
def get_feed_context(self, object_list):
post_comment_counts = {
int(page[2:]): count
for page, count in Comment.objects.filter(
page__in=["b:%d" % post.id for post in object_list], hidden=False
)
.values_list("page")
.annotate(count=Count("page"))
.order_by()
}
return {"post_comment_counts": post_comment_counts}
def get_context_data(self, **kwargs):
context = super(OrganizationHome, self).get_context_data(**kwargs)
context["title"] = self.organization.name
@ -292,15 +280,6 @@ class OrganizationHome(OrganizationHomeView, FeedView):
+ "."
+ get_current_site(self.request).domain
)
context["post_comment_counts"] = {
int(page[2:]): count
for page, count in Comment.objects.filter(
page__in=["b:%d" % post.id for post in context["posts"]], hidden=False
)
.values_list("page")
.annotate(count=Count("page"))
.order_by()
}
now = timezone.now()
visible_contests = (

View file

@ -29,7 +29,7 @@
<a href="{{ url('blog_post', post.id, post.slug) }}#comments" class="blog-comment-count-link">
<i class="fa fa-comments blog-comment-icon"></i>
<span class="blog-comment-count">
{{- post_comment_counts[post.id] or 0 -}}
{{- post.comments.filter(hidden=False).count() or 0 -}}
</span>
</a>
</span>