one notification per week

This commit is contained in:
j 2023-12-10 10:06:45 +00:00
parent 381186afba
commit 1f9676fdab

View file

@ -5,6 +5,7 @@ import tempfile
from celery.schedules import crontab from celery.schedules import crontab
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
from django.core.cache import cache
from . import utils from . import utils
from ..signalbot import rpc from ..signalbot import rpc
@ -22,9 +23,11 @@ def send_week():
monday = views.get_monday(now) monday = views.get_monday(now)
week, archive = models.Item.public(now) week, archive = models.Item.public(now)
week_obj = models.Week.objects.filter(monday=monday).first() week_obj = models.Week.objects.filter(monday=monday).first()
if not week_obj: notified_key = "week-%s-notified" % monday
if not week_obj and not cache.get(notified_key):
message = "no title for week, can not send out email please add: %s/admin/item/week/add/?monday=%s" % (settings.URL, monday) message = "no title for week, can not send out email please add: %s/admin/item/week/add/?monday=%s" % (settings.URL, monday)
r = rpc.send(message, group=settings.SIGNAL_MODERATORS_GROUP) r = rpc.send(message, group=settings.SIGNAL_MODERATORS_GROUP)
cache.set(notified_key, True, 24*60*60)
elif week.filter(announced=None).exists(): elif week.filter(announced=None).exists():
logger.error("waiting for last item of the week to be public") logger.error("waiting for last item of the week to be public")
elif not week_obj.published: elif not week_obj.published: