From faba118955af670fbcfbe2f5f6ba62b80b2371d5 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 5 May 2020 17:23:33 +0200 Subject: [PATCH] Send mails to organizers properly --- apps/tournament/models.py | 15 +++++++++++++++ apps/tournament/views.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/tournament/models.py b/apps/tournament/models.py index 041ef3d..552ece1 100644 --- a/apps/tournament/models.py +++ b/apps/tournament/models.py @@ -110,6 +110,21 @@ class Tournament(models.Model): verbose_name = _("tournament") verbose_name_plural = _("tournaments") + def send_mail_to_organizers(self, template_name, subject="Contact TFJM²", **kwargs): + context = kwargs + context["tournament"] = self + for user in self.organizers.all(): + context["user"] = user + message = render_to_string("mail_templates/" + template_name + ".txt", context=context) + message_html = render_to_string("mail_templates/" + template_name + ".html", context=context) + send_mail(subject, message, "contact@tfjm.org", [user.email], html_message=message_html) + from member.models import TFJMUser + for user in TFJMUser.objects.get(is_superuser=True).all(): + context["user"] = user + message = render_to_string("mail_templates/" + template_name + ".txt", context=context) + message_html = render_to_string("mail_templates/" + template_name + ".html", context=context) + send_mail(subject, message, "contact@tfjm.org", [user.email], html_message=message_html) + def __str__(self): return self.name diff --git a/apps/tournament/views.py b/apps/tournament/views.py index 82528ed..e2614ca 100644 --- a/apps/tournament/views.py +++ b/apps/tournament/views.py @@ -142,7 +142,7 @@ class TeamDetailView(LoginRequiredMixin, DetailView): elif "request_validation" in request.POST and request.user.participates: team.validation_status = "1waiting" team.save() - team.send_mail("request_validation", "Demande de validation TFJM²") + team.tournament.send_mail_to_organizers("request_validation", "Demande de validation TFJM²", team=team) return redirect('tournament:team_detail', pk=team.pk) elif "validate" in request.POST and request.user.organizes: team.validation_status = "2valid"