From: Gael Le Mignot Date: Wed, 10 Jun 2020 12:16:20 +0000 (+0200) Subject: Command to send Webclass notifications X-Git-Tag: 1.4.3~75^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=81147ff958ef42639da0217977ad1c1ab42fc713;p=teleforma.git Command to send Webclass notifications --- diff --git a/teleforma/management/commands/teleforma-webclass-send-notifications.py b/teleforma/management/commands/teleforma-webclass-send-notifications.py new file mode 100644 index 00000000..80546f7a --- /dev/null +++ b/teleforma/management/commands/teleforma-webclass-send-notifications.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from teleforma.webclass.models import * +from teleforma.models import * + +from postman.utils import email_visitor, notify_user +from postman.models import Message + +WARN_DELAY_MAX = 15 +WARN_DELAY_MIN = 5 + +class Command(BaseCommand): + help = "Send the Webclass will start notifications" + + def handle(self, *args, **options): + now = datetime.datetime.now() + dow = now.weekday() + begin = now + datetime.timedelta(minutes=WARN_DELAY_MIN) + end = now + datetime.timedelta(minutes=WARN_DELAY_MAX) + slots = WebclassSlot.objects.filter(day = dow, + start_hour__gte = begin.time(), + start_hour__lt = end.time()) + site = Site.objects.all()[0] + admin = User.objects.get(username = 'Admin-CRFPA') + date = now.strftime('%d/%m/%Y') + for slot in slots: + hour = slot.start_hour.strftime('%Hh%M') + print("Sending notifications for %s:%s (%s)" % (slot.webclass.course, + slot.start_hour, + slot.id)) + subject = "Webclass_%s_%s_%s" % (slot.webclass.course, + date, hour) + + body = """Votre Webclasse va commencer.""" + + users = slot.participants.all() + for user in users: + print(" => %s" % user) + msg = Message(subject = subject, + body = body, + sender = admin, + recipient = user) + msg.moderation_status = 'a' + msg.save() + notify_user(msg, 'acceptance', site) +