Sending confirmation email also for the EDS section

This commit is contained in:
alazo 2018-06-08 13:50:09 +02:00 committed by Claude Paroz
parent e3a9ef7443
commit 02fb84700f
4 changed files with 56 additions and 4 deletions

View file

@ -117,7 +117,7 @@ class CandidateAdmin(admin.ModelAdmin):
if not obj.pk:
return ''
return format_html(
'<a class="button" href="{}">Confirmation de réception FE + EDE</a>&nbsp;'
'<a class="button" href="{}">Confirmation de linscription FE + ES</a>&nbsp;'
'<a class="button" href="{}">Validation enseignants EDE</a>&nbsp;'
'<a class="button" href="{}">Convocation aux examens EDE</a>&nbsp;'
'<a class="button" href="{}">Impression du résumé du dossier EDE</a>',

View file

@ -105,6 +105,7 @@ class CandidateTests(TestCase):
ede = Section.objects.create(name='EDE')
ase = Section.objects.create(name='ASE')
eds = Section.objects.create(name='EDS')
Candidate.objects.bulk_create([
# A mail should NOT be sent for those first 2
Candidate(
@ -117,6 +118,8 @@ class CandidateTests(TestCase):
email='henri@example.org', deposite_date=date.today()),
Candidate(first_name='Joé', last_name='Glatz', gender='F', section=ase,
email='joe@example.org', deposite_date=date.today()),
Candidate(first_name='John', last_name='Durand', gender='M', section=eds,
email='john@example.org', deposite_date=date.today()),
])
self.client.login(username='me', password='mepassword')
cand1 = Candidate.objects.get(last_name='Simth')
@ -180,6 +183,35 @@ tél. 032 886 33 00"""
# One was already set, 2 new.
self.assertEqual(Candidate.objects.filter(confirmation_date__isnull=False).count(), 3)
mail.outbox = []
cand5 = Candidate.objects.get(last_name='Durand')
response = self.client.get(reverse('candidate-confirmation', args=[cand5.pk]))
data = response.context['form'].initial
response = self.client.post(
reverse('candidate-confirmation', args=[cand5.pk]), data=data, follow=True
)
self.assertEqual(len(mail.outbox), 1)
# Logged-in user also receives as Bcc
self.assertEqual(mail.outbox[0].recipients(), ['john@example.org', 'me@example.org'])
self.assertEqual(mail.outbox[0].body, """Monsieur John Durand,
Par ce courriel, nous vous confirmons la bonne réception de vos documents de candidature à la formation Education sociale, dipl. ES et vous remercions de lintérêt que vous portez à notre institution.
Votre dossier sera traité début octobre 2018 et des nouvelles vous seront communiquées par courriel.
Dans lintervalle, nous vous adressons, Monsieur, nos salutations les plus cordiales.
Secrétariat de la filière Education sociale, dipl. ES
Hans Schmid
me@example.org
tél. 032 886 33 00"""
)
# One was already set, 2 new.
self.assertEqual(Candidate.objects.filter(confirmation_date__isnull=False).count(), 4)
def test_send_confirmation_error(self):
ede = Section.objects.create(name='EDE')
henri = Candidate.objects.create(

View file

@ -25,14 +25,17 @@ class CandidateConfirmationView(EmailConfirmationBaseView):
class ConfirmationView(CandidateConfirmationView):
success_message = "Le message de confirmation a été envoyé pour le candidat {person}"
"""
Email confirming the receipt of the registration form
"""
success_message = "Une confirmation d'inscription a été envoyée à {person}"
candidate_date_field = 'confirmation_date'
title = "Confirmation de réception de dossier"
def get(self, request, *args, **kwargs):
candidate = Candidate.objects.get(pk=self.kwargs['pk'])
if candidate.section != 'EDE' and not candidate.section in {'ASA', 'ASE', 'ASSC'}:
messages.error(request, "Ce formulaire n'est disponible que pour les candidats EDE ou FE")
if candidate.section not in {'ASA', 'ASE', 'ASSC', 'EDE', 'EDS'}:
messages.error(request, "Ce formulaire n'est disponible que pour les candidats FE ou ES")
elif candidate.confirmation_date:
messages.error(request, 'Une confirmation a déjà été envoyée!')
elif candidate.canceled_file:
@ -48,6 +51,8 @@ class ConfirmationView(CandidateConfirmationView):
to = [candidate.email]
if candidate.section == 'EDE':
src_email = 'email/candidate_confirm_EDE.txt'
elif candidate.section == 'EDS':
src_email = 'email/candidate_confirm_EDS.txt'
elif candidate.section in {'ASA', 'ASE', 'ASSC'}:
src_email = 'email/candidate_confirm_FE.txt'
if candidate.corporation and candidate.corporation.email: