From 618cfdfebf1d346e780c795fe77b01820245ec49 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 5 Dec 2017 15:51:28 +0100 Subject: [PATCH] Added a special confirmation email for EDE section --- candidats/admin.py | 8 ++++- candidats/tests.py | 36 ++++++++++++++----- templates/email/candidate_confirm_EDE.txt | 14 ++++++++ ...e_confirm.txt => candidate_confirm_FE.txt} | 0 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 templates/email/candidate_confirm_EDE.txt rename templates/email/{candidate_confirm.txt => candidate_confirm_FE.txt} (100%) diff --git a/candidats/admin.py b/candidats/admin.py index 6591956..782111f 100644 --- a/candidats/admin.py +++ b/candidats/admin.py @@ -46,18 +46,24 @@ def send_confirmation_mail(modeladmin, request, queryset): for candidate in queryset.filter( deposite_date__isnull=False, date_confirmation_mail__isnull=True, canceled_file=False): to = [candidate.email] + if candidate.corporation and candidate.corporation.email: to.append(candidate.corporation.email) if candidate.instructor and candidate.instructor.email: to.append(candidate.instructor.email) context = { + 'candidate_civility': candidate.civility, 'candidate_name': " ".join([candidate.civility, candidate.first_name, candidate.last_name]), 'section': candidate.section, 'sender_name': " ".join([request.user.first_name, request.user.last_name]), 'sender_email': from_email, } - body = loader.render_to_string('email/candidate_confirm.txt', context) + + if candidate.section == 'EDE': + body = loader.render_to_string('email/candidate_confirm_EDE.txt', context) + else: + body = loader.render_to_string('email/candidate_confirm_FE.txt', context) try: send_mail(subject, body, from_email, to, fail_silently=False) except Exception as err: diff --git a/candidats/tests.py b/candidats/tests.py index 2b56d27..38ace98 100644 --- a/candidats/tests.py +++ b/candidats/tests.py @@ -17,22 +17,23 @@ class CandidateTests(TestCase): ) def test_send_confirmation_mail(self): - sect = Section.objects.create(name='EDE') + ede = Section.objects.create(name='EDE') + ase = Section.objects.create(name='ASE') Candidate.objects.bulk_create([ # A mail should NOT be sent for those first 4 Candidate( - first_name='Sara', last_name='Hitz', gender='F', section=sect, + first_name='Sara', last_name='Hitz', gender='F', section=ede, deposite_date=None), Candidate( - first_name='Jill', last_name='Simth', gender='F', section=sect, + first_name='Jill', last_name='Simth', gender='F', section=ede, date_confirmation_mail=date.today()), - Candidate(first_name='Hervé', last_name='Bern', gender='M', section=sect, + Candidate(first_name='Hervé', last_name='Bern', gender='M', section=ede, canceled_file=True), - Candidate(first_name='Frank', last_name='Pit', gender='M', section=sect, email=''), + Candidate(first_name='Frank', last_name='Pit', gender='M', section=ede, email=''), # Good - Candidate(first_name='Joé', last_name='Glatz', gender='F', section=sect, + Candidate(first_name='Joé', last_name='Glatz', gender='F', section=ase, email='joe@example.org', deposite_date=date.today()), - Candidate(first_name='Henri', last_name='Dupond', gender='M', section=sect, + Candidate(first_name='Henri', last_name='Dupond', gender='M', section=ede, email='henri@example.org', deposite_date=date.today()), ]) change_url = reverse('admin:candidats_candidate_changelist') @@ -44,9 +45,26 @@ class CandidateTests(TestCase): self.assertEqual(len(mail.outbox), 2) self.assertEqual(mail.outbox[0].recipients(), ['henri@example.org']) self.assertEqual(mail.outbox[1].recipients(), ['joe@example.org']) - self.assertEqual(mail.outbox[0].body, """Madame, Monsieur, + # Mail content differ depending on the section + self.assertEqual(mail.outbox[0].body, """Monsieur, -Nous vous confirmons la bonne réception de l'inscription de Monsieur Henri Dupond dans la filière EDE pour l'année scolaire à venir. +Par ce courriel, nous vous confirmons la bonne réception de votre dossier de candidature à la formation ES d’Educateur-trice de l’enfance et vous remercions de l’intérêt que vous portez à notre institution. + +Celui-ci sera traité et des nouvelles vous seront communiquées par courriel durant la 2ème quinzaine du mois de février. + +Dans l’intervalle, nous vous adressons, Monsieur, nos salutations les plus cordiales. + + +Secrétariat de l'EPC +tél. 032 886 33 00 + +Hans Schmid +me@example.org +""".format() + ) + self.assertEqual(mail.outbox[1].body, """Madame, Monsieur, + +Nous vous confirmons la bonne réception de l'inscription de Madame Joé Glatz dans la filière ASE pour l'année scolaire à venir. Nous nous tenons à votre disposition pour tout renseignement complémentaire et vous prions de recevoir, Madame, Monsieur, nos salutations les plus cordiales. diff --git a/templates/email/candidate_confirm_EDE.txt b/templates/email/candidate_confirm_EDE.txt new file mode 100644 index 0000000..58bf84c --- /dev/null +++ b/templates/email/candidate_confirm_EDE.txt @@ -0,0 +1,14 @@ +{{ candidate_civility }}, + +Par ce courriel, nous vous confirmons la bonne réception de votre dossier de candidature à la formation ES d’Educateur-trice de l’enfance et vous remercions de l’intérêt que vous portez à notre institution. + +Celui-ci sera traité et des nouvelles vous seront communiquées par courriel durant la 2ème quinzaine du mois de février. + +Dans l’intervalle, nous vous adressons, {{ candidate_civility }}, nos salutations les plus cordiales. + + +Secrétariat de l'EPC +tél. 032 886 33 00 + +{{ sender_name }} +{{ sender_email }} diff --git a/templates/email/candidate_confirm.txt b/templates/email/candidate_confirm_FE.txt similarity index 100% rename from templates/email/candidate_confirm.txt rename to templates/email/candidate_confirm_FE.txt