From 7abdccfbdb3da53341e06ff6edb60e0d8061eaf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Tue, 27 Sep 2016 17:57:53 +0200 Subject: [PATCH] =?UTF-8?q?Meilleure=20gestion=20des=20donn=C3=A9es=20mail?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les valeurs de champs FROM, REPLY-TO et BCC des mails envoyés par GestioCOF sont enregistrées dans un dictionnaire `settings.MAIL_DATA` plutôt que d'être toutes enregistrées comme variables indépendantes --- bda/models.py | 17 +++++++++++------ cof/settings_dev.py | 21 ++++++++++++--------- gestioncof/petits_cours_views.py | 6 +++--- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/bda/models.py b/bda/models.py index 1074e58b..cc96e525 100644 --- a/bda/models.py +++ b/bda/models.py @@ -119,8 +119,9 @@ class Spectacle(models.Model): 'show': self}) mail_tot = mail.EmailMessage( mail_object, mail_body, - settings.RAPPEL_FROM, [member.email], - [], headers={'Reply-To': settings.RAPPEL_REPLY_TO}) + settings.MAIL_DATA['rappels']['FROM'], [member.email], + [], headers={ + 'Reply-To': settings.MAIL_DATA['rappels']['REPLYTO']}) mails_to_send.append(mail_tot) # On envoie les mails connection = mail.get_connection() @@ -273,8 +274,10 @@ class SpectacleRevente(models.Model): 'revente': self}) mail_tot = mail.EmailMessage( mail_object, mail_body, - settings.REVENTE_FROM, [participant.user.email], - [], headers={'Reply-To': settings.REVENTE_REPLY_TO}) + settings.MAIL_DATA['revente']['FROM'], + [participant.user.email], + [], headers={ + 'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']}) mails_to_send.append(mail_tot) connection = mail.get_connection() @@ -294,8 +297,10 @@ class SpectacleRevente(models.Model): 'mail': self.attribution.participant.user.email}) mail_tot = mail.EmailMessage( mail_object, mail_body, - settings.REVENTE_FROM, [participant.user.email], - [], headers={'Reply-To': settings.REVENTE_REPLY_TO}) + settings.MAIL_DATA['revente']['FROM'], + [participant.user.email], + [], headers={ + 'Reply-To': settings.MAIL_DATA['revente']['REPLYTO']}) mails_to_send.append(mail_tot) connection = mail.get_connection() diff --git a/cof/settings_dev.py b/cof/settings_dev.py index 7d270648..5e092635 100644 --- a/cof/settings_dev.py +++ b/cof/settings_dev.py @@ -145,15 +145,18 @@ ADMIN_MEDIA_PREFIX = '/static/grappelli/' GRAPPELLI_ADMIN_HEADLINE = "GestioCOF" GRAPPELLI_ADMIN_TITLE = "GestioCOF" -PETITS_COURS_FROM = "Le COF " -PETITS_COURS_BCC = "archivescof@gmail.com" -PETITS_COURS_REPLYTO = "cof@ens.fr" - -RAPPEL_FROM = 'Le BdA ' -RAPPEL_REPLY_TO = RAPPEL_FROM - -REVENTE_FROM = 'BDA-Revente ' -REVENTE_REPLY_TO = REVENTE_FROM +MAIL_DATA = { + 'petits_cours': { + 'FROM': "Le COF ", + 'BCC': "archivescof@gmail.com", + 'REPLYTO': "cof@ens.fr"}, + 'rappels': { + 'FROM': 'Le BdA ', + 'REPLYTO': 'Le BdA '}, + 'revente': { + 'FROM': 'BDA-Revente ', + 'REPLYTO': 'BDA-Revente '}, +} LOGIN_URL = "/gestion/login" LOGIN_REDIRECT_URL = "/gestion/" diff --git a/gestioncof/petits_cours_views.py b/gestioncof/petits_cours_views.py index 1a31115d..e9fe511e 100644 --- a/gestioncof/petits_cours_views.py +++ b/gestioncof/petits_cours_views.py @@ -282,9 +282,9 @@ def _traitement_post(request, demande): {"proposals": proposals_list, "unsatisfied": unsatisfied, "extra": extra}) - frommail = settings.PETITS_COURS_FROM - bccaddress = settings.PETITS_COURS_BCC - replyto = settings.PETITS_COURS_REPLYTO + frommail = settings.MAIL_DATA['petits_cours']['FROM'] + bccaddress = settings.MAIL_DATA['petits_cours']['BCC'] + replyto = settings.MAIL_DATA['petits_cours']['REPLYTO'] mails_to_send = [] for (user, msg) in proposed_mails: msg = EmailMessage("Petits cours ENS par le COF", msg,