Fixed #13494 -- Correctly concat an email subject prefix with a translation string. Thanks, hcarvalhoalves and Andi Albrecht.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14157 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-10-11 22:27:45 +00:00
parent 2ed554bd92
commit d739737015
2 changed files with 22 additions and 2 deletions

View File

@ -87,7 +87,7 @@ def mail_admins(subject, message, fail_silently=False, connection=None):
"""Sends a message to the admins, as defined by the ADMINS setting."""
if not settings.ADMINS:
return
EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message,
settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS],
connection=connection).send(fail_silently=fail_silently)
@ -96,7 +96,7 @@ def mail_managers(subject, message, fail_silently=False, connection=None):
"""Sends a message to the managers, as defined by the MANAGERS setting."""
if not settings.MANAGERS:
return
EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message,
settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS],
connection=connection).send(fail_silently=fail_silently)

View File

@ -343,3 +343,23 @@ class MailTests(TestCase):
settings.ADMINS = old_admins
settings.MANAGERS = old_managers
def test_mail_prefix(self):
"""Test prefix argument in manager/admin mail."""
# Regression for #13494.
old_admins = settings.ADMINS
old_managers = settings.MANAGERS
settings.ADMINS = settings.MANAGERS = [('nobody','nobody@example.com')]
mail_managers(ugettext_lazy('Subject'), 'Content')
self.assertEqual(len(mail.outbox), 1)
message = mail.outbox[0]
self.assertEqual(message.subject, '[Django] Subject')
mail.outbox = []
mail_admins(ugettext_lazy('Subject'), 'Content')
self.assertEqual(len(mail.outbox), 1)
message = mail.outbox[0]
self.assertEqual(message.subject, '[Django] Subject')
settings.ADMINS = old_admins
settings.MANAGERS = old_managers