mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-03 23:22:54 +02:00
Send mails
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import os
|
||||
|
||||
from django.core.mail import send_mail
|
||||
from django.db import models
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -201,6 +203,15 @@ class Team(models.Model):
|
||||
verbose_name_plural = _("teams")
|
||||
unique_together = (('name', 'year',), ('trigram', 'year',),)
|
||||
|
||||
def send_mail(self, template_name, subject="Contact TFJM²", **kwargs):
|
||||
context = kwargs
|
||||
context["team"] = self
|
||||
for user in self.users.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.trigram + " -- " + self.name
|
||||
|
||||
|
Reference in New Issue
Block a user