Browse Source

Merge branch 'jd-fee-call-from-admin-contact' of jocelyn/coin into master

jocelyn 9 years ago
parent
commit
6c3c8831e7
3 changed files with 41 additions and 14 deletions
  1. 10 0
      README.md
  2. 27 12
      coin/members/models.py
  3. 4 2
      coin/utils.py

+ 10 - 0
README.md

@@ -172,6 +172,16 @@ Some bits of configuration are done in `settings.py`: LDAP branches, RSS feeds
 to display on the home page, and so on.  Lastly, it is possible to override
 to display on the home page, and so on.  Lastly, it is possible to override
 all Coin templates (i.e. for user views and emails), see below.
 all Coin templates (i.e. for user views and emails), see below.
 
 
+Sending emails
+--------------
+
+Coin sends mails, you might want to customize the sender address:
+
+- `DEFAULT_FROM_EMAIL` app-wide setting
+- *administrative email* field, from *ISPDatabase* app, if set, will take
+  precedence over `DEFAULT_FROM_EMAIL` for administrative emails (welcome email
+  and membership fees), will take precedence (if filled).
+
 Cron tasks
 Cron tasks
 ----------
 ----------
 
 

+ 27 - 12
coin/members/models.py

@@ -258,10 +258,18 @@ class Member(CoinLdapSyncMixin, AbstractUser):
         """ Envoie le courriel de bienvenue à ce membre """
         """ Envoie le courriel de bienvenue à ce membre """
         from coin.isp_database.models import ISPInfo
         from coin.isp_database.models import ISPInfo
 
 
-        utils.send_templated_email(to=self.email,
-                   subject_template='members/emails/welcome_email_subject.txt',
-                   body_template='members/emails/welcome_email.html',
-                   context={'member': self, 'branding':ISPInfo.objects.first()})
+        isp_info = ISPInfo.objects.first()
+
+        kwargs = {}
+        if isp_info.administrative_email:
+            kwargs['from_email'] = isp_info.administrative_email
+
+        utils.send_templated_email(
+            to=self.email,
+            subject_template='members/emails/welcome_email_subject.txt',
+            body_template='members/emails/welcome_email.html',
+            context={'member': self, 'branding': isp_info},
+            **kwargs)
 
 
     def send_call_for_membership_fees_email(self, auto=False):
     def send_call_for_membership_fees_email(self, auto=False):
         """ Envoie le courriel d'appel à cotisation du membre
         """ Envoie le courriel d'appel à cotisation du membre
@@ -271,18 +279,25 @@ class Member(CoinLdapSyncMixin, AbstractUser):
         from dateutil.relativedelta import relativedelta
         from dateutil.relativedelta import relativedelta
         from coin.isp_database.models import ISPInfo
         from coin.isp_database.models import ISPInfo
 
 
+        isp_info = ISPInfo.objects.first()
+        kwargs = {}
+        if isp_info.administrative_email:
+            kwargs['from_email'] = isp_info.administrative_email
+
         # Si le dernier courriel de relance a été envoyé il y a moins de trois
         # Si le dernier courriel de relance a été envoyé il y a moins de trois
         # semaines, n'envoi pas un nouveau courriel
         # semaines, n'envoi pas un nouveau courriel
         if (not self.date_last_call_for_membership_fees_email
         if (not self.date_last_call_for_membership_fees_email
             or (self.date_last_call_for_membership_fees_email
             or (self.date_last_call_for_membership_fees_email
-               <= timezone.now() + relativedelta(weeks=-3))):
-            utils.send_templated_email(to=self.email,
-               subject_template='members/emails/call_for_membership_fees_subject.txt',
-               body_template='members/emails/call_for_membership_fees.html',
-               context={'member': self, 'branding':ISPInfo.objects.first(),
-                        'membership_info_url': settings.MEMBER_MEMBERSHIP_INFO_URL,
-                        'today': datetime.date.today,
-                        'auto_sent': auto})
+                <= timezone.now() + relativedelta(weeks=-3))):
+            utils.send_templated_email(
+                to=self.email,
+                subject_template='members/emails/call_for_membership_fees_subject.txt',
+                body_template='members/emails/call_for_membership_fees.html',
+                context={'member': self, 'branding': isp_info,
+                         'membership_info_url': settings.MEMBER_MEMBERSHIP_INFO_URL,
+                         'today': datetime.date.today,
+                         'auto_sent': auto},
+                **kwargs)
             # Sauvegarde en base la date du dernier envoi de mail de relance
             # Sauvegarde en base la date du dernier envoi de mail de relance
             self.date_last_call_for_membership_fees_email = timezone.now()
             self.date_last_call_for_membership_fees_email = timezone.now()
             self.save()
             self.save()

+ 4 - 2
coin/utils.py

@@ -47,9 +47,11 @@ def ldap_hash(password):
         return password
         return password
 
 
 
 
-def send_templated_email(to, subject_template, body_template, context={}, attachements=[]):
+def send_templated_email(to, subject_template, body_template, context={}, attachements=[], **kwargs):
     """
     """
     Send a multialternative email based on html and optional txt template.
     Send a multialternative email based on html and optional txt template.
+
+    :param **kwargs: extra-args pased as-is to EmailMultiAlternatives()
     """
     """
 
 
     # Ensure arrays when needed
     # Ensure arrays when needed
@@ -84,7 +86,7 @@ def send_templated_email(to, subject_template, body_template, context={}, attach
         text_content = html2text.html2text(html_content)
         text_content = html2text.html2text(html_content)
 
 
     # make multipart email default : text, alternative : html
     # make multipart email default : text, alternative : html
-    msg = EmailMultiAlternatives(subject=subject, body=text_content, to=to)
+    msg = EmailMultiAlternatives(subject=subject, body=text_content, to=to, **kwargs)
     msg.attach_alternative(html_content, "text/html")
     msg.attach_alternative(html_content, "text/html")
 
 
     # Set attachements
     # Set attachements