From a19a79531679cfac08583c6375ef3b8a39f7fbb8 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 26 Jun 2022 14:24:38 +0700 Subject: [PATCH] Add notification for pending blogs --- judge/views/organization.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/judge/views/organization.py b/judge/views/organization.py index 8154eb9..bd68c65 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -51,6 +51,7 @@ from judge.models import ( Problem, Profile, Contest, + Notification, ) from judge import event_poster as event from judge.utils.ranker import ranker @@ -801,6 +802,24 @@ class AddOrganizationBlog( revisions.set_comment(_("Added from site")) revisions.set_user(self.request.user) + + link = reverse( + "edit_organization_blog", + args=[self.organization.id, self.organization.slug, self.object.id], + ) + html = ( + f'{self.object.title} - {self.organization.name}' + ) + for user in self.organization.admins.all(): + if user.id == self.request.profile.id: + continue + notification = Notification( + owner=user, + author=self.request.profile, + category="Add blog", + html_link=html, + ) + notification.save() return res @@ -860,6 +879,24 @@ class EditOrganizationBlog( res = super(EditOrganizationBlog, self).form_valid(form) revisions.set_comment(_("Edited from site")) revisions.set_user(self.request.user) + + link = reverse( + "edit_organization_blog", + args=[self.organization.id, self.organization.slug, self.object.id], + ) + html = ( + f'{self.object.title} - {self.organization.name}' + ) + for user in self.organization.admins.all(): + if user.id == self.request.profile.id: + continue + notification = Notification( + owner=user, + author=self.request.profile, + category="Edit blog", + html_link=html, + ) + notification.save() return res