Add mail send when confirming. Closes #19
This commit is contained in:
parent
68de1aefea
commit
d3d7c0b4a1
7 changed files with 33 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
import os
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
def authorized_mails(request):
|
def authorized_mails(request):
|
||||||
return {'authorized_mails': os.getenv('AUTHORIZED_MAILS', '').split(',')}
|
return {'authorized_mails': settings.AUTHORIZED_MAILS}
|
||||||
|
|
|
@ -79,7 +79,25 @@ class Teacher(BaseModel):
|
||||||
if reply_to:
|
if reply_to:
|
||||||
msg.reply_to = reply_to
|
msg.reply_to = reply_to
|
||||||
msg.attach_alternative(
|
msg.attach_alternative(
|
||||||
render_to_string('manuels/email.html', {'link': link, 'teacher': self}), "text/html"
|
render_to_string('manuels/emails_link.html', {'link': link, 'teacher': self}), "text/html"
|
||||||
|
)
|
||||||
|
msg.send()
|
||||||
|
|
||||||
|
def send_confirmation(self, request):
|
||||||
|
dest = settings.LIBRARIAN_EMAILS
|
||||||
|
link = request.build_absolute_uri(reverse('home_page'))
|
||||||
|
msg = EmailMultiAlternatives(
|
||||||
|
subject="Gestion des manuels scolaires - Confirmation d'un coordonnateur",
|
||||||
|
body=f'Bonjour,\n'
|
||||||
|
f'{self.first_name} a confirmé ses listes sur {link}',
|
||||||
|
from_email=settings.SERVER_EMAIL,
|
||||||
|
to=dest,
|
||||||
|
)
|
||||||
|
reply_to = [os.getenv('REPLY_TO')]
|
||||||
|
if reply_to:
|
||||||
|
msg.reply_to = reply_to
|
||||||
|
msg.attach_alternative(
|
||||||
|
render_to_string('manuels/emails_confirmation.html', {'link': link, 'teacher': self}), "text/html"
|
||||||
)
|
)
|
||||||
msg.send()
|
msg.send()
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Danger</h4>
|
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Danger</h4>
|
||||||
<p class="mb-0">
|
<p class="mb-0">
|
||||||
<strong>Êtes-vous certain·e de vouloir confirmer vos listes ?
|
<strong>Êtes-vous certain·e de vouloir confirmer vos listes ?
|
||||||
Cette action est définitive : vous ne pourrez plus les modifier ensuite.</strong>
|
Cette action est définitive : vous ne ne serez plus en mesure de les modifier ensuite.</strong>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<form action="" method="post" class="form">
|
<form action="" method="post" class="form">
|
||||||
|
|
6
manuels/templates/manuels/emails_confirmation.html
Normal file
6
manuels/templates/manuels/emails_confirmation.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<html>
|
||||||
|
<p>Bonjour,</p>
|
||||||
|
<p>
|
||||||
|
{{ teacher.full_name }} a confirmé ses listes sur <a href="{{ link }}">{{ link }}</a>
|
||||||
|
</p>
|
||||||
|
</html>
|
|
@ -198,4 +198,6 @@ class ConfirmTeacherView(BaseTeacherView, UpdateView):
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
self.object.has_confirmed_list = True
|
self.object.has_confirmed_list = True
|
||||||
self.object.save()
|
self.object.save()
|
||||||
|
self.object.send_confirmation(request=self.request)
|
||||||
|
messages.success(self.request, "Vos listes ont été validées. Votre documentaliste a été notifiée par email.")
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -41,6 +41,9 @@ ADMINS = [('Gabriel', os.getenv('ADMIN_EMAIL')), ]
|
||||||
SERVER_EMAIL = os.getenv('SERVER_EMAIL')
|
SERVER_EMAIL = os.getenv('SERVER_EMAIL')
|
||||||
EMAIL_SUBJECT_PREFIX = '[Manuels] '
|
EMAIL_SUBJECT_PREFIX = '[Manuels] '
|
||||||
|
|
||||||
|
AUTHORIZED_EMAILS = os.getenv('AUTHORIZED_EMAILS', '').split(',')
|
||||||
|
LIBRARIAN_EMAILS = os.getenv('LIBRARIAN_EMAILS', '').split(',')
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
|
Loading…
Reference in a new issue