Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored June 28, 2011
3  django/contrib/auth/models.py
@@ -86,7 +86,7 @@ def __unicode__(self):
86 86
         return self.name
87 87
 
88 88
 class UserManager(models.Manager):
89  
-    def create_user(self, username, email, password=None):
  89
+    def create_user(self, username, email=None, password=None):
90 90
         """
91 91
         Creates and saves a User with the given username, email and password.
92 92
         """
@@ -94,6 +94,7 @@ def create_user(self, username, email, password=None):
94 94
 
95 95
         # Normalize the address by lowercasing the domain part of the email
96 96
         # address.
  97
+        email = email or ''
97 98
         try:
98 99
             email_name, domain_part = email.strip().split('@', 1)
99 100
         except ValueError:
11  django/contrib/auth/tests/basic.py
@@ -39,6 +39,17 @@ def test_user(self):
39 39
         u2 = User.objects.create_user('testuser2', 'test2@example.com')
40 40
         self.assertFalse(u.has_usable_password())
41 41
 
  42
+    def test_user_no_email(self):
  43
+        "Check that users can be created without an email"
  44
+        u = User.objects.create_user('testuser1')
  45
+        u.email = ''
  46
+
  47
+        u2 = User.objects.create_user('testuser2', email='')
  48
+        u2.email = ''
  49
+
  50
+        u3 = User.objects.create_user('testuser3', email=None)
  51
+        u3.email = ''
  52
+
42 53
     def test_anonymous_user(self):
43 54
         "Check the properties of the anonymous user"
44 55
         a = AnonymousUser()
5  docs/topics/auth.txt
@@ -277,7 +277,10 @@ Manager functions
277 277
     The :class:`~django.contrib.auth.models.User` model has a custom manager
278 278
     that has the following helper functions:
279 279
 
280  
-    .. method:: models.UserManager.create_user(username, email, password=None)
  280
+    .. method:: models.UserManager.create_user(username, email=None, password=None)
  281
+
  282
+        .. versionchanged:: 1.4
  283
+           The ``email`` parameter was made optional.
281 284
 
282 285
         Creates, saves and returns a :class:`~django.contrib.auth.models.User`.
283 286
 

0 notes on commit f54135f

Please sign in to comment.
Something went wrong with that request. Please try again.