Add notif for comment page author

This commit is contained in:
cuom1999 2022-05-17 22:34:08 -05:00
parent 1533607551
commit 6047d292dc
2 changed files with 31 additions and 3 deletions

View file

@ -131,10 +131,22 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
# add notification for reply
if comment.parent and comment.parent.author != comment.author:
notification_rep = Notification(
notification_reply = Notification(
owner=comment.parent.author, comment=comment, category="Reply"
)
notification_rep.save()
notification_reply.save()
# add notification for page authors
page_authors = comment.page_object.authors.all()
for user in page_authors:
if user == comment.author:
continue
notification = Notification(
owner=user, comment=comment, category="Comment"
)
notification.save()
# except Exception:
# pass
add_mention_notifications(comment)

View file

@ -15,7 +15,7 @@ from reversion.models import Version
from judge.models.contest import Contest
from judge.models.interface import BlogPost
from judge.models.problem import Problem
from judge.models.problem import Problem, Solution
from judge.models.profile import Profile
from judge.utils.cachedict import CacheDict
@ -171,6 +171,22 @@ class Comment(MPTTModel):
def get_absolute_url(self):
return "%s#comment-%d" % (self.link, self.id)
@cached_property
def page_object(self):
try:
page = self.page
if page.startswith("p:"):
return Problem.objects.get(code=page[2:])
elif page.startswith("c:"):
return Contest.objects.get(key=page[2:])
elif page.startswith("b:"):
return BlogPost.objects.get(id=page[2:])
elif page.startswith("s:"):
return Solution.objects.get(problem__code=page[2:])
return None
except ObjectDoesNotExist:
return None
def __str__(self):
return "%(page)s by %(user)s" % {
"page": self.page,