Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
3 weeks ago
|
from django.core.mail import EmailMessage
|
||
|
from django.http import HttpRequest
|
||
|
from django.urls import reverse
|
||
|
|
||
|
from korektury.models import Komentar, Oprava
|
||
|
from personalni.models import Organizator
|
||
|
|
||
|
|
||
|
def send_email_notification_komentar(oprava: Oprava, autor: Organizator, request: HttpRequest):
|
||
|
''' Rozesle e-mail pri pridani komentare / opravy,
|
||
|
ktery obsahuje text vlakna opravy.
|
||
|
'''
|
||
|
|
||
|
# parametry e-mailu
|
||
|
#odkaz = "https://mam.mff.cuni.cz/korektury/{}/".format(oprava.pdf.pk)
|
||
|
odkaz = request.build_absolute_uri(reverse('korektury', kwargs={'pdf': oprava.pdf.pk}))
|
||
|
odkaz = f"{odkaz}#op{oprava.id}-pointer"
|
||
|
from_email = 'korekturovatko@mam.mff.cuni.cz'
|
||
|
subject = 'Nová korektura od {} v {}'.format(autor, oprava.pdf.nazev)
|
||
|
texty = [(oprava.autor.osoba.plne_jmeno(),oprava.text)]
|
||
|
for kom in Komentar.objects.filter(oprava=oprava):
|
||
|
texty.append((kom.autor.osoba.plne_jmeno(),kom.text))
|
||
|
optext = "\n\n\n".join([": ".join(t) for t in texty])
|
||
|
text = u"Text komentáře:\n\n{}\n\n=== Konec textu komentáře ===\n\
|
||
|
\nodkaz do korekturovátka: {}\n\
|
||
|
\nVaše korekturovátko\n".format(optext, odkaz)
|
||
|
|
||
|
# Prijemci e-mailu
|
||
|
emails = set()
|
||
|
# e-mail autora korektury
|
||
|
email = oprava.autor.osoba.email
|
||
|
if email:
|
||
|
emails.add(email)
|
||
|
|
||
|
# nalezeni e-mailu na autory komentaru
|
||
|
for komentar in oprava.komentar_set.all():
|
||
|
email_komentujiciho = komentar.autor.osoba.email
|
||
|
if email_komentujiciho:
|
||
|
emails.add(email_komentujiciho)
|
||
|
|
||
|
# zodpovedni orgove
|
||
|
for org in oprava.pdf.orgove.all():
|
||
|
email_zobpovedny = org.osoba.email
|
||
|
if email_zobpovedny:
|
||
|
emails.add(email_zobpovedny)
|
||
|
|
||
|
# odstran e-mail autora opravy
|
||
|
email = autor.osoba.email
|
||
|
if email:
|
||
|
emails.discard(email)
|
||
|
|
||
|
EmailMessage(
|
||
|
subject=subject,
|
||
|
body=text,
|
||
|
from_email=from_email,
|
||
|
to=list(emails),
|
||
|
).send()
|