Add mail send when confirming. Closes #19

This commit is contained in:
Gabriel Augendre 2018-06-02 18:03:18 +02:00
parent 68de1aefea
commit d3d7c0b4a1
7 changed files with 33 additions and 4 deletions

View file

@ -1,5 +1,5 @@
import os
from django.conf import settings
def authorized_mails(request):
return {'authorized_mails': os.getenv('AUTHORIZED_MAILS', '').split(',')}
return {'authorized_mails': settings.AUTHORIZED_MAILS}

View file

@ -79,7 +79,25 @@ class Teacher(BaseModel):
if reply_to:
msg.reply_to = reply_to
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()

View file

@ -15,7 +15,7 @@
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Danger</h4>
<p class="mb-0">
<strong>Êtes-vous certain&centerdot;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>
</div>
<form action="" method="post" class="form">

View 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>

View file

@ -198,4 +198,6 @@ class ConfirmTeacherView(BaseTeacherView, UpdateView):
response = super().form_valid(form)
self.object.has_confirmed_list = True
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

View file

@ -41,6 +41,9 @@ ADMINS = [('Gabriel', os.getenv('ADMIN_EMAIL')), ]
SERVER_EMAIL = os.getenv('SERVER_EMAIL')
EMAIL_SUBJECT_PREFIX = '[Manuels] '
AUTHORIZED_EMAILS = os.getenv('AUTHORIZED_EMAILS', '').split(',')
LIBRARIAN_EMAILS = os.getenv('LIBRARIAN_EMAILS', '').split(',')
# Application definition
INSTALLED_APPS = [