Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit f54135fa4dc9fd45d86ea2944191d58e00725779 1 parent d400ff4
Chris Beaven SmileyChris authored
3  django/contrib/auth/models.py
View
@@ -86,7 +86,7 @@ def __unicode__(self):
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 @@ def create_user(self, username, email, password=None):
# 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:
11 django/contrib/auth/tests/basic.py
View
@@ -39,6 +39,17 @@ def test_user(self):
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()
5 docs/topics/auth.txt
View
@@ -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`.
Please sign in to comment.
Something went wrong with that request. Please try again.