summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Beaven <smileychris@gmail.com>2011-06-28 04:29:48 +0000
committerChris Beaven <smileychris@gmail.com>2011-06-28 04:29:48 +0000
commitf54135fa4dc9fd45d86ea2944191d58e00725779 (patch)
treea9bb37190020a6aa8c9a8fb1adb03ce9f8b01e08
parentd400ff4f139c05d205066ae07a30ac9156cb8468 (diff)
Make the email parameter of User.objects.create_user optional.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16472 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/auth/models.py3
-rw-r--r--django/contrib/auth/tests/basic.py11
-rw-r--r--docs/topics/auth.txt5
3 files changed, 17 insertions, 2 deletions
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index e9a6cd2e47..4656946a9a 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -86,7 +86,7 @@ class Group(models.Model):
return self.name
class UserManager(models.Manager):
- def create_user(self, username, email, password=None):
+ def create_user(self, username, email=None, password=None):
"""
Creates and saves a User with the given username, email and password.
"""
@@ -94,6 +94,7 @@ class UserManager(models.Manager):
# Normalize the address by lowercasing the domain part of the email
# address.
+ email = email or ''
try:
email_name, domain_part = email.strip().split('@', 1)
except ValueError:
diff --git a/django/contrib/auth/tests/basic.py b/django/contrib/auth/tests/basic.py
index 44738f7d07..6d4f6664c4 100644
--- a/django/contrib/auth/tests/basic.py
+++ b/django/contrib/auth/tests/basic.py
@@ -39,6 +39,17 @@ class BasicTestCase(TestCase):
u2 = User.objects.create_user('testuser2', 'test2@example.com')
self.assertFalse(u.has_usable_password())
+ def test_user_no_email(self):
+ "Check that users can be created without an email"
+ u = User.objects.create_user('testuser1')
+ u.email = ''
+
+ u2 = User.objects.create_user('testuser2', email='')
+ u2.email = ''
+
+ u3 = User.objects.create_user('testuser3', email=None)
+ u3.email = ''
+
def test_anonymous_user(self):
"Check the properties of the anonymous user"
a = AnonymousUser()
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
index c1947f61e1..a50e24c0df 100644
--- a/docs/topics/auth.txt
+++ b/docs/topics/auth.txt
@@ -277,7 +277,10 @@ Manager functions
The :class:`~django.contrib.auth.models.User` model has a custom manager
that has the following helper functions:
- .. method:: models.UserManager.create_user(username, email, password=None)
+ .. method:: models.UserManager.create_user(username, email=None, password=None)
+
+ .. versionchanged:: 1.4
+ The ``email`` parameter was made optional.
Creates, saves and returns a :class:`~django.contrib.auth.models.User`.