From f0c34fe70c783d4c7e6c31f75496bcba5f4b21c6 Mon Sep 17 00:00:00 2001 From: Skia Date: Mon, 25 Sep 2017 12:35:56 +0200 Subject: [PATCH] sas: add permanent notification for SAS moderation Signed-off-by: Skia --- core/models.py | 4 ++++ sas/models.py | 9 +++++++++ sith/settings.py | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index 45b8f78f..8573fd4a 100644 --- a/core/models.py +++ b/core/models.py @@ -725,6 +725,10 @@ class SithFile(models.Model): super(SithFile, self).save(*args, **kwargs) if copy_rights: self.copy_rights() + if self.is_in_sas: + for u in RealGroup.objects.filter(id=settings.SITH_GROUP_SAS_ADMIN_ID).first().users.all(): + Notification(user=u, url=reverse("sas:moderation"), + type="SAS_MODERATION", param="1").save() def apply_rights_recursively(self, only_folders=False): children = self.children.all() diff --git a/sas/models.py b/sas/models.py index 33ef8899..583c3f59 100644 --- a/sas/models.py +++ b/sas/models.py @@ -26,6 +26,7 @@ from django.db import models from django.core.urlresolvers import reverse from django.conf import settings from django.utils.translation import ugettext_lazy as _ +from django.utils import timezone from PIL import Image from io import BytesIO @@ -162,6 +163,14 @@ class Album(SithFile): self.file.name = self.name + '/thumb.jpg' self.save() +def sas_notification_callback(notif): + count = Picture.objects.filter(is_moderated=False).count() + if count: + notif.viewed = False + notif.param = "%s" % count + notif.date = timezone.now() + else: + notif.viewed = True class PeoplePictureRelation(models.Model): """ diff --git a/sith/settings.py b/sith/settings.py index d5ce3c17..779eb04e 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -556,7 +556,7 @@ SITH_NOTIFICATIONS = [ ('MAILING_MODERATION', _("A new mailing list needs to be moderated")), ('NEWS_MODERATION', _("There are %s fresh news to be moderated")), ('FILE_MODERATION', _("New files to be moderated")), - ('SAS_MODERATION', _("New pictures/album to be moderated in the SAS")), + ('SAS_MODERATION', _("There are %s pictures to be moderated in the SAS")), ('NEW_PICTURES', _("You've been identified on some pictures")), ('REFILLING', _("You just refilled of %s €")), ('SELLING', _("You just bought %s")), @@ -568,6 +568,7 @@ SITH_NOTIFICATIONS = [ # The callback must take the notif object as first and single argument. SITH_PERMANENT_NOTIFICATIONS = { 'NEWS_MODERATION': 'com.models.news_notification_callback', + 'SAS_MODERATION': 'sas.models.sas_notification_callback', } SITH_QUICK_NOTIF = {