From: yomguy Date: Tue, 3 Jul 2012 22:22:49 +0000 (+0200) Subject: add email notification copy to admins X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=7f54fe3abb0b8d4592291259842c42d2ee971002;p=django-postman.git add email notification copy to admins --- diff --git a/postman/utils.py b/postman/utils.py index b12cbe5..2c4c6d7 100644 --- a/postman/utils.py +++ b/postman/utils.py @@ -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) +