]> git.parisson.com Git - django-postman.git/commitdiff
add email notification copy to admins
authoryomguy <yomguy@parisson.com>
Tue, 3 Jul 2012 22:22:49 +0000 (00:22 +0200)
committeryomguy <yomguy@parisson.com>
Tue, 3 Jul 2012 22:22:49 +0000 (00:22 +0200)
postman/utils.py

index b12cbe528c55807795114f37b8c9034dffa395c0..2c4c6d7832e0b0cb3c52a5f93cb59ab0e6ce5fd0 100644 (file)
@@ -24,7 +24,7 @@ name = getattr(settings, 'POSTMAN_MAILER_APP', 'mailer')
 if name and name in settings.INSTALLED_APPS:
     send_mail = __import__(name, globals(), locals(), ['send_mail']).send_mail
 else:
-    from django.core.mail import send_mail
+    from django.core.mail import send_mail, mail_admins
 
 # to disable email notification to users
 DISABLE_USER_EMAILING = getattr(settings, 'POSTMAN_DISABLE_USER_EMAILING', False)
@@ -64,13 +64,14 @@ def format_subject(subject):
 def email(subject_template, message_template, recipient_list, object, action=None):
     """Compose and send an email."""
     site = Site.objects.get_current()
-    ctx_dict = {'site': site, 'object': object, 'action': action}
+    ctx_dict = {'site': site, 'object': object, 'action': action, 'usr': object.sender}
     subject = render_to_string(subject_template, ctx_dict)
     # Email subject *must not* contain newlines
     subject = ''.join(subject.splitlines())
     message = render_to_string(message_template, ctx_dict)
     # during the development phase, consider using the setting: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
     send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True)
+    mail_admins(subject, message)
 
 def email_visitor(object, action):
     """Email a visitor."""
@@ -91,4 +92,5 @@ def notify_user(object, action):
         notification.send(users=[user], label=label, extra_context={'message': object, 'action': action})
     else:
         if not DISABLE_USER_EMAILING and user.email and user.is_active:
-            email('postman/email_user_subject.txt', 'postman/email_user.txt', [user.email], object, action)
+            email('postman/email_user_subject.txt', 'postman/email_user.txt',[user.email], object, action)
+