Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -575,6 +575,7 @@ answer newbie questions, and generally made Django that much better: Aaron Swartz <http://www.aaronsw.com/> Ville Säävuori <http://www.unessa.net/> Mart Sõmermaa <http://mrts.pri.ee/> Susan Tan <susan.tan.fleckerl@gmail.com> Christian Tanzer <tanzer@swing.co.at> Tyler Tarabula <tyler.tarabula@gmail.com> Tyson Tate <tyson@fallingbullets.com> Loading django/contrib/auth/models.py +2 −2 Original line number Diff line number Diff line Loading @@ -400,11 +400,11 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin): "Returns the short name for the user." return self.first_name def email_user(self, subject, message, from_email=None): def email_user(self, subject, message, from_email=None, **kwargs): """ Sends an email to this User. """ send_mail(subject, message, from_email, [self.email]) send_mail(subject, message, from_email, [self.email], **kwargs) class User(AbstractUser): Loading django/contrib/auth/tests/test_models.py +25 −1 Original line number Diff line number Diff line from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, User, UserManager from django.contrib.auth.models import AbstractUser, Group, User, UserManager from django.contrib.auth.tests.utils import skipIfCustomUser from django.core import mail from django.db.models.signals import post_save from django.test import TestCase from django.test.utils import override_settings Loading Loading @@ -73,6 +74,29 @@ class UserManagerTestCase(TestCase): User.objects.create_user, username='') class AbstractUserTestCase(TestCase): def test_email_user(self): # valid send_mail parameters kwargs = { "fail_silently": False, "auth_user": None, "auth_password": None, "connection": None, "html_message": None, } abstract_user = AbstractUser(email='foo@bar.com') abstract_user.email_user(subject="Subject here", message="This is a message", from_email="from@domain.com", **kwargs) # Test that one message has been sent. self.assertEqual(len(mail.outbox), 1) # Verify that test email contains the correct attributes: message = mail.outbox[0] self.assertEqual(message.subject, "Subject here") self.assertEqual(message.body, "This is a message") self.assertEqual(message.from_email, "from@domain.com") self.assertEqual(message.to, [abstract_user.email]) class IsActiveTestCase(TestCase): """ Tests the behavior of the guaranteed is_active attribute Loading docs/ref/contrib/auth.txt +6 −1 Original line number Diff line number Diff line Loading @@ -215,11 +215,16 @@ Methods (the Django app label). If the user is inactive, this method will always return ``False``. .. method:: email_user(subject, message, from_email=None) .. method:: email_user(subject, message, from_email=None, **kwargs) Sends an email to the user. If ``from_email`` is ``None``, Django uses the :setting:`DEFAULT_FROM_EMAIL`. .. versionchanged:: 1.7 Any ``**kwargs`` are passed to the underlying :meth:`~django.core.mail.send_mail()` call. Manager methods --------------- Loading docs/releases/1.7.txt +4 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,10 @@ Minor features Each radio button or checkbox includes an ``id_for_label`` attribute to output the element's ID. * Any ``**kwargs`` passed to :meth:`~django.contrib.auth.models.User.email_user()` are passed to the underlying :meth:`~django.core.mail.send_mail()` call. Backwards incompatible changes in 1.7 ===================================== Loading Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -575,6 +575,7 @@ answer newbie questions, and generally made Django that much better: Aaron Swartz <http://www.aaronsw.com/> Ville Säävuori <http://www.unessa.net/> Mart Sõmermaa <http://mrts.pri.ee/> Susan Tan <susan.tan.fleckerl@gmail.com> Christian Tanzer <tanzer@swing.co.at> Tyler Tarabula <tyler.tarabula@gmail.com> Tyson Tate <tyson@fallingbullets.com> Loading
django/contrib/auth/models.py +2 −2 Original line number Diff line number Diff line Loading @@ -400,11 +400,11 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin): "Returns the short name for the user." return self.first_name def email_user(self, subject, message, from_email=None): def email_user(self, subject, message, from_email=None, **kwargs): """ Sends an email to this User. """ send_mail(subject, message, from_email, [self.email]) send_mail(subject, message, from_email, [self.email], **kwargs) class User(AbstractUser): Loading
django/contrib/auth/tests/test_models.py +25 −1 Original line number Diff line number Diff line from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, User, UserManager from django.contrib.auth.models import AbstractUser, Group, User, UserManager from django.contrib.auth.tests.utils import skipIfCustomUser from django.core import mail from django.db.models.signals import post_save from django.test import TestCase from django.test.utils import override_settings Loading Loading @@ -73,6 +74,29 @@ class UserManagerTestCase(TestCase): User.objects.create_user, username='') class AbstractUserTestCase(TestCase): def test_email_user(self): # valid send_mail parameters kwargs = { "fail_silently": False, "auth_user": None, "auth_password": None, "connection": None, "html_message": None, } abstract_user = AbstractUser(email='foo@bar.com') abstract_user.email_user(subject="Subject here", message="This is a message", from_email="from@domain.com", **kwargs) # Test that one message has been sent. self.assertEqual(len(mail.outbox), 1) # Verify that test email contains the correct attributes: message = mail.outbox[0] self.assertEqual(message.subject, "Subject here") self.assertEqual(message.body, "This is a message") self.assertEqual(message.from_email, "from@domain.com") self.assertEqual(message.to, [abstract_user.email]) class IsActiveTestCase(TestCase): """ Tests the behavior of the guaranteed is_active attribute Loading
docs/ref/contrib/auth.txt +6 −1 Original line number Diff line number Diff line Loading @@ -215,11 +215,16 @@ Methods (the Django app label). If the user is inactive, this method will always return ``False``. .. method:: email_user(subject, message, from_email=None) .. method:: email_user(subject, message, from_email=None, **kwargs) Sends an email to the user. If ``from_email`` is ``None``, Django uses the :setting:`DEFAULT_FROM_EMAIL`. .. versionchanged:: 1.7 Any ``**kwargs`` are passed to the underlying :meth:`~django.core.mail.send_mail()` call. Manager methods --------------- Loading
docs/releases/1.7.txt +4 −0 Original line number Diff line number Diff line Loading @@ -152,6 +152,10 @@ Minor features Each radio button or checkbox includes an ``id_for_label`` attribute to output the element's ID. * Any ``**kwargs`` passed to :meth:`~django.contrib.auth.models.User.email_user()` are passed to the underlying :meth:`~django.core.mail.send_mail()` call. Backwards incompatible changes in 1.7 ===================================== Loading