mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
d400ff4f13
commit
f54135fa4d
|
@ -86,7 +86,7 @@ class Group(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class UserManager(models.Manager):
|
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.
|
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
|
# Normalize the address by lowercasing the domain part of the email
|
||||||
# address.
|
# address.
|
||||||
|
email = email or ''
|
||||||
try:
|
try:
|
||||||
email_name, domain_part = email.strip().split('@', 1)
|
email_name, domain_part = email.strip().split('@', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -39,6 +39,17 @@ class BasicTestCase(TestCase):
|
||||||
u2 = User.objects.create_user('testuser2', 'test2@example.com')
|
u2 = User.objects.create_user('testuser2', 'test2@example.com')
|
||||||
self.assertFalse(u.has_usable_password())
|
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):
|
def test_anonymous_user(self):
|
||||||
"Check the properties of the anonymous user"
|
"Check the properties of the anonymous user"
|
||||||
a = AnonymousUser()
|
a = AnonymousUser()
|
||||||
|
|
|
@ -277,7 +277,10 @@ Manager functions
|
||||||
The :class:`~django.contrib.auth.models.User` model has a custom manager
|
The :class:`~django.contrib.auth.models.User` model has a custom manager
|
||||||
that has the following helper functions:
|
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`.
|
Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue