From 02fb84700fb9bfd857c2e723ccc7c96f322f616c Mon Sep 17 00:00:00 2001 From: alazo Date: Fri, 8 Jun 2018 13:50:09 +0200 Subject: [PATCH] Sending confirmation email also for the EDS section --- candidats/admin.py | 2 +- candidats/tests.py | 32 +++++++++++++++++++++++ candidats/views.py | 11 +++++--- templates/email/candidate_confirm_EDS.txt | 15 +++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 templates/email/candidate_confirm_EDS.txt diff --git a/candidats/admin.py b/candidats/admin.py index 70666d6..18835d8 100644 --- a/candidats/admin.py +++ b/candidats/admin.py @@ -117,7 +117,7 @@ class CandidateAdmin(admin.ModelAdmin): if not obj.pk: return '' return format_html( - 'Confirmation de réception FE + EDE ' + 'Confirmation de l’inscription FE + ES ' 'Validation enseignants EDE ' 'Convocation aux examens EDE ' 'Impression du résumé du dossier EDE', diff --git a/candidats/tests.py b/candidats/tests.py index 132b2f4..ed2a677 100644 --- a/candidats/tests.py +++ b/candidats/tests.py @@ -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 l’inté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 l’intervalle, 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( diff --git a/candidats/views.py b/candidats/views.py index 97b3646..46fabb5 100644 --- a/candidats/views.py +++ b/candidats/views.py @@ -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: diff --git a/templates/email/candidate_confirm_EDS.txt b/templates/email/candidate_confirm_EDS.txt new file mode 100644 index 0000000..79f3f52 --- /dev/null +++ b/templates/email/candidate_confirm_EDS.txt @@ -0,0 +1,15 @@ +{{ candidate.civility }} {{ candidate.first_name }} {{ candidate.last_name }}, + +Par ce courriel, nous vous confirmons la bonne réception de vos documents de candidature à la formation {{ candidate.section_option }} et vous remercions de l’inté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 l’intervalle, nous vous adressons, {{ candidate.civility }}, nos salutations les plus cordiales. + + + +Secrétariat de la filière Education sociale, dipl. ES +{{ sender.first_name }} {{ sender.last_name }} +{{ sender.email }} +tél. 032 886 33 00 \ No newline at end of file