From 5aaa2760a98cfdf39e395d1d31b0ccda345c05ba Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Thu, 2 Jul 2020 11:07:45 +0200 Subject: [PATCH] =?UTF-8?q?Rozes=C3=ADl=C3=A1n=C3=AD=20zve=C5=99ejn=C4=9Bn?= =?UTF-8?q?=C3=A9ho=20=C4=8D=C3=ADsla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/views.py | 2 +- mamweb/settings_common.py | 2 +- mamweb/settings_prod.py | 2 +- seminar/models.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/korektury/views.py b/korektury/views.py index c3f22569..bca5b66a 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -162,7 +162,7 @@ class KorekturyView(generic.TemplateView): if email: emails.discard(email) - if not settings.SEND_EMAIL_NOTIFICATIONS: + if not settings.POSLI_MAILOVOU_NOTIFIKACI: print("Poslal bych upozornění na tyto adresy: ", " ".join(emails)) return diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 62cd7fe7..510b35f3 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -279,4 +279,4 @@ CISLO_IMG_DIR = os.path.join('cislo', 'img') # E-MAIL NOTIFICATIONS -SEND_EMAIL_NOTIFICATIONS = False +POSLI_MAILOVOU_NOTIFIKACI = False diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index 1c223842..0374d88b 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -66,4 +66,4 @@ LOGGING['handlers']['registration_error_log']['filename'] = '/home/mam-web/logs/ # E-MAIL NOTIFICATIONS -SEND_EMAIL_NOTIFICATIONS = True +POSLI_MAILOVOU_NOTIFIKACI = True diff --git a/seminar/models.py b/seminar/models.py index deb0c9b9..f148ca64 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -32,6 +32,8 @@ from seminar.treelib import safe_pred from polymorphic.models import PolymorphicModel +from django.core.mail import EmailMessage +from seminar.utils import aktivniResitele class SeminarModelBase(models.Model): @@ -539,9 +541,43 @@ class Cislo(SeminarModelBase): return None return c + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.__original_verejne = self.verejne_db + + def posli_cislo_mailem(self): + # parametry e-mailu + odkaz = self.get_absolute_url() + + poslat_z_mailu = 'zadani@mam.mff.cuni.cz' + predmet = 'Vyšlo číslo {}'.format(self.kod()) + text_mailu = 'Ahoj,\n' \ + 'na adrese {} najdete nejnovější číslo.\n' \ + 'Vaše M&M\n'.format(odkaz) + + # Prijemci e-mailu + emaily = map(lambda r: r.osoba.email, aktivniResitele(self )) + + if not settings.POSLI_MAILOVOU_NOTIFIKACI: + print("Poslal bych upozornění na tyto adresy: ", " ".join(emaily)) + return + + email = EmailMessage( + subject=predmet, + body=text_mailu, + from_email=poslat_z_mailu, + bcc=list(emaily) + #bcc = příjemci skryté kopie + ) + + email.send() + def save(self, *args, **kwargs): super().save(*args, **kwargs) self.vygeneruj_nahled() + # Při zveřejnění pošle mail + if self.verejne_db and not self.__original_verejne: + self.posli_cislo_mailem() # *Node.save() aktualizuje název *Nodu. try: self.cislonode.save()