diff options
| author | Chris Beaven <smileychris@gmail.com> | 2011-06-28 04:29:48 +0000 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2011-06-28 04:29:48 +0000 |
| commit | f54135fa4dc9fd45d86ea2944191d58e00725779 (patch) | |
| tree | a9bb37190020a6aa8c9a8fb1adb03ce9f8b01e08 /django | |
| parent | d400ff4f139c05d205066ae07a30ac9156cb8468 (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
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/models.py | 3 | ||||
| -rw-r--r-- | django/contrib/auth/tests/basic.py | 11 |
2 files changed, 13 insertions, 1 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() |
