mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-07-09 02:50:19 +02:00
Send a mail to teams when the team got validated
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
import os
|
||||
from io import BytesIO
|
||||
from zipfile import ZipFile
|
||||
|
||||
from django.core.mail import send_mail
|
||||
|
||||
from corres2math.lists import get_sympa_client
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
@ -152,9 +155,21 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
||||
if "validate" in self.request.POST:
|
||||
self.object.participation.valid = True
|
||||
self.object.participation.save()
|
||||
mail_context = dict(team=self.object, message=form.cleaned_data["message"])
|
||||
mail_plain = render_to_string("participation/mails/team_validated.txt", mail_context)
|
||||
mail_html = render_to_string("participation/mails/team_validated.html", mail_context)
|
||||
send_mail("[Corres2math] Équipe validée", mail_plain, None,
|
||||
[f"equipe-{self.object.trigram.lower()}@{os.getenv('SYMPA_HOST', 'localhost')}"],
|
||||
html_message=mail_html)
|
||||
elif "invalidate" in self.request.POST:
|
||||
self.object.participation.valid = None
|
||||
self.object.participation.save()
|
||||
mail_context = dict(team=self.object, message=form.cleaned_data["message"])
|
||||
mail_plain = render_to_string("participation/mails/team_not_validated.txt", mail_context)
|
||||
mail_html = render_to_string("participation/mails/team_not_validated.html", mail_context)
|
||||
send_mail("[Corres2math] Équipe non validée", mail_plain, None,
|
||||
[f"equipe-{self.object.trigram.lower()}@{os.getenv('SYMPA_HOST', 'localhost')}"],
|
||||
html_message=mail_html)
|
||||
else:
|
||||
form.add_error(None, _("You must specify if you validate the registration or not."))
|
||||
return self.form_invalid(form)
|
||||
|
Reference in New Issue
Block a user