Code

Ticket #19596: ticket19596.diff

File ticket19596.diff, 14.5 KB (added by apollo13, 18 months ago)
Line 
1diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
2index db99c94..703fd25 100644
3--- a/django/contrib/auth/backends.py
4+++ b/django/contrib/auth/backends.py
5@@ -13,7 +13,7 @@ class ModelBackend(object):
6     def authenticate(self, username=None, password=None):
7         try:
8             UserModel = get_user_model()
9-            user = UserModel.objects.get_by_natural_key(username)
10+            user = UserModel._default_manager.get_by_natural_key(username)
11             if user.check_password(password):
12                 return user
13         except UserModel.DoesNotExist:
14@@ -64,7 +64,7 @@ class ModelBackend(object):
15     def get_user(self, user_id):
16         try:
17             UserModel = get_user_model()
18-            return UserModel.objects.get(pk=user_id)
19+            return UserModel._default_manager.get(pk=user_id)
20         except UserModel.DoesNotExist:
21             return None
22 
23diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
24index 8529112..cbce8ad 100644
25--- a/django/contrib/auth/forms.py
26+++ b/django/contrib/auth/forms.py
27@@ -89,7 +89,7 @@ class UserCreationForm(forms.ModelForm):
28         # but it sets a nicer error message than the ORM. See #13147.
29         username = self.cleaned_data["username"]
30         try:
31-            User.objects.get(username=username)
32+            User._default_manager.get(username=username)
33         except User.DoesNotExist:
34             return username
35         raise forms.ValidationError(self.error_messages['duplicate_username'])
36@@ -217,7 +217,7 @@ class PasswordResetForm(forms.Form):
37         """
38         UserModel = get_user_model()
39         email = self.cleaned_data["email"]
40-        self.users_cache = UserModel.objects.filter(email__iexact=email)
41+        self.users_cache = UserModel._default_manager.filter(email__iexact=email)
42         if not len(self.users_cache):
43             raise forms.ValidationError(self.error_messages['unknown'])
44         if not any(user.is_active for user in self.users_cache):
45diff --git a/django/contrib/auth/handlers/modwsgi.py b/django/contrib/auth/handlers/modwsgi.py
46index 5ee4d60..a26d621 100644
47--- a/django/contrib/auth/handlers/modwsgi.py
48+++ b/django/contrib/auth/handlers/modwsgi.py
49@@ -18,7 +18,7 @@ def check_password(environ, username, password):
50 
51     try:
52         try:
53-            user = UserModel.objects.get_by_natural_key(username)
54+            user = UserModel._default_manager.get_by_natural_key(username)
55         except UserModel.DoesNotExist:
56             return None
57         if not user.is_active:
58@@ -37,7 +37,7 @@ def groups_for_user(environ, username):
59 
60     try:
61         try:
62-            user = UserModel.objects.get_by_natural_key(username)
63+            user = UserModel._default_manager.get_by_natural_key(username)
64         except UserModel.DoesNotExist:
65             return []
66         try:
67diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
68index ce5d57f..a77bba0 100644
69--- a/django/contrib/auth/management/__init__.py
70+++ b/django/contrib/auth/management/__init__.py
71@@ -174,7 +174,7 @@ def get_default_username(check_db=True):
72     # Don't return the default username if it is already taken.
73     if check_db and default_username:
74         try:
75-            auth_app.User.objects.get(username=default_username)
76+            auth_app.User._default_manager.get(username=default_username)
77         except auth_app.User.DoesNotExist:
78             pass
79         else:
80diff --git a/django/contrib/auth/management/commands/changepassword.py b/django/contrib/auth/management/commands/changepassword.py
81index ff38836..3240b0f 100644
82--- a/django/contrib/auth/management/commands/changepassword.py
83+++ b/django/contrib/auth/management/commands/changepassword.py
84@@ -33,7 +33,7 @@ class Command(BaseCommand):
85         UserModel = get_user_model()
86 
87         try:
88-            u = UserModel.objects.using(options.get('database')).get(**{
89+            u = UserModel._default_manager.using(options.get('database')).get(**{
90                     UserModel.USERNAME_FIELD: username
91                 })
92         except UserModel.DoesNotExist:
93diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py
94index 216d56d..7b4764a 100644
95--- a/django/contrib/auth/management/commands/createsuperuser.py
96+++ b/django/contrib/auth/management/commands/createsuperuser.py
97@@ -95,7 +95,7 @@ class Command(BaseCommand):
98                         username = None
99                         continue
100                     try:
101-                        self.UserModel.objects.db_manager(database).get_by_natural_key(username)
102+                        self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
103                     except self.UserModel.DoesNotExist:
104                         pass
105                     else:
106@@ -134,6 +134,6 @@ class Command(BaseCommand):
107 
108         user_data[self.UserModel.USERNAME_FIELD] = username
109         user_data['password'] = password
110-        self.UserModel.objects.db_manager(database).create_superuser(**user_data)
111+        self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
112         if verbosity >= 1:
113             self.stdout.write("Superuser created successfully.")
114diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py
115index 71f18d3..074374c 100644
116--- a/django/contrib/auth/tests/auth_backends.py
117+++ b/django/contrib/auth/tests/auth_backends.py
118@@ -34,7 +34,7 @@ class BaseModelBackendTest(object):
119         ContentType.objects.clear_cache()
120 
121     def test_has_perm(self):
122-        user = self.UserModel.objects.get(pk=self.user.pk)
123+        user = self.UserModel._default_manager.get(pk=self.user.pk)
124         self.assertEqual(user.has_perm('auth.test'), False)
125         user.is_staff = True
126         user.save()
127@@ -53,14 +53,14 @@ class BaseModelBackendTest(object):
128         self.assertEqual(user.has_perm('auth.test'), False)
129 
130     def test_custom_perms(self):
131-        user = self.UserModel.objects.get(pk=self.user.pk)
132+        user = self.UserModel._default_manager.get(pk=self.user.pk)
133         content_type = ContentType.objects.get_for_model(Group)
134         perm = Permission.objects.create(name='test', content_type=content_type, codename='test')
135         user.user_permissions.add(perm)
136         user.save()
137 
138         # reloading user to purge the _perm_cache
139-        user = self.UserModel.objects.get(pk=self.user.pk)
140+        user = self.UserModel._default_manager.get(pk=self.user.pk)
141         self.assertEqual(user.get_all_permissions() == set(['auth.test']), True)
142         self.assertEqual(user.get_group_permissions(), set([]))
143         self.assertEqual(user.has_module_perms('Group'), False)
144@@ -71,7 +71,7 @@ class BaseModelBackendTest(object):
145         perm = Permission.objects.create(name='test3', content_type=content_type, codename='test3')
146         user.user_permissions.add(perm)
147         user.save()
148-        user = self.UserModel.objects.get(pk=self.user.pk)
149+        user = self.UserModel._default_manager.get(pk=self.user.pk)
150         self.assertEqual(user.get_all_permissions(), set(['auth.test2', 'auth.test', 'auth.test3']))
151         self.assertEqual(user.has_perm('test'), False)
152         self.assertEqual(user.has_perm('auth.test'), True)
153@@ -81,7 +81,7 @@ class BaseModelBackendTest(object):
154         group.permissions.add(perm)
155         group.save()
156         user.groups.add(group)
157-        user = self.UserModel.objects.get(pk=self.user.pk)
158+        user = self.UserModel._default_manager.get(pk=self.user.pk)
159         exp = set(['auth.test2', 'auth.test', 'auth.test3', 'auth.test_group'])
160         self.assertEqual(user.get_all_permissions(), exp)
161         self.assertEqual(user.get_group_permissions(), set(['auth.test_group']))
162@@ -93,7 +93,7 @@ class BaseModelBackendTest(object):
163 
164     def test_has_no_object_perm(self):
165         """Regressiontest for #12462"""
166-        user = self.UserModel.objects.get(pk=self.user.pk)
167+        user = self.UserModel._default_manager.get(pk=self.user.pk)
168         content_type = ContentType.objects.get_for_model(Group)
169         perm = Permission.objects.create(name='test', content_type=content_type, codename='test')
170         user.user_permissions.add(perm)
171@@ -106,7 +106,7 @@ class BaseModelBackendTest(object):
172 
173     def test_get_all_superuser_permissions(self):
174         "A superuser has all permissions. Refs #14795"
175-        user = self.UserModel.objects.get(pk=self.superuser.pk)
176+        user = self.UserModel._default_manager.get(pk=self.superuser.pk)
177         self.assertEqual(len(user.get_all_permissions()), len(Permission.objects.all()))
178 
179 
180@@ -151,13 +151,13 @@ class ExtensionUserModelBackendTest(BaseModelBackendTest, TestCase):
181     UserModel = ExtensionUser
182 
183     def create_users(self):
184-        self.user = ExtensionUser.objects.create_user(
185+        self.user = ExtensionUser._default_manager.create_user(
186             username='test',
187             email='test@example.com',
188             password='test',
189             date_of_birth=date(2006, 4, 25)
190         )
191-        self.superuser = ExtensionUser.objects.create_superuser(
192+        self.superuser = ExtensionUser._default_manager.create_superuser(
193             username='test2',
194             email='test2@example.com',
195             password='test',
196@@ -178,12 +178,12 @@ class CustomPermissionsUserModelBackendTest(BaseModelBackendTest, TestCase):
197     UserModel = CustomPermissionsUser
198 
199     def create_users(self):
200-        self.user = CustomPermissionsUser.objects.create_user(
201+        self.user = CustomPermissionsUser._default_manager.create_user(
202             email='test@example.com',
203             password='test',
204             date_of_birth=date(2006, 4, 25)
205         )
206-        self.superuser = CustomPermissionsUser.objects.create_superuser(
207+        self.superuser = CustomPermissionsUser._default_manager.create_superuser(
208             email='test2@example.com',
209             password='test',
210             date_of_birth=date(1976, 11, 8)
211diff --git a/django/contrib/auth/tests/custom_user.py b/django/contrib/auth/tests/custom_user.py
212index 7e042e4..8cc57d4 100644
213--- a/django/contrib/auth/tests/custom_user.py
214+++ b/django/contrib/auth/tests/custom_user.py
215@@ -42,7 +42,7 @@ class CustomUser(AbstractBaseUser):
216     is_admin = models.BooleanField(default=False)
217     date_of_birth = models.DateField()
218 
219-    objects = CustomUserManager()
220+    custom_objects = CustomUserManager()
221 
222     USERNAME_FIELD = 'email'
223     REQUIRED_FIELDS = ['date_of_birth']
224@@ -88,7 +88,7 @@ class CustomUser(AbstractBaseUser):
225 class ExtensionUser(AbstractUser):
226     date_of_birth = models.DateField()
227 
228-    objects = UserManager()
229+    custom_objects = UserManager()
230 
231     REQUIRED_FIELDS = AbstractUser.REQUIRED_FIELDS + ['date_of_birth']
232 
233@@ -112,7 +112,7 @@ class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin):
234     email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
235     date_of_birth = models.DateField()
236 
237-    objects = CustomPermissionsUserManager()
238+    custom_objects = CustomPermissionsUserManager()
239 
240     USERNAME_FIELD = 'email'
241     REQUIRED_FIELDS = ['date_of_birth']
242@@ -136,7 +136,7 @@ class IsActiveTestUser1(AbstractBaseUser):
243     """
244     username = models.CharField(max_length=30, unique=True)
245 
246-    objects = BaseUserManager()
247+    custom_objects = BaseUserManager()
248 
249     USERNAME_FIELD = 'username'
250 
251diff --git a/django/contrib/auth/tests/handlers.py b/django/contrib/auth/tests/handlers.py
252index 04ab46f..41063aa 100644
253--- a/django/contrib/auth/tests/handlers.py
254+++ b/django/contrib/auth/tests/handlers.py
255@@ -42,7 +42,7 @@ class ModWsgiHandlerTestCase(TransactionTestCase):
256         with custom user installed
257         """
258 
259-        CustomUser.objects.create_user('test@example.com', '1990-01-01', 'test')
260+        CustomUser._default_manager.create_user('test@example.com', '1990-01-01', 'test')
261 
262         # User not in database
263         self.assertTrue(check_password({}, 'unknown', '') is None)
264diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py
265index 02939e3..42f14d6 100644
266--- a/django/contrib/auth/tests/management.py
267+++ b/django/contrib/auth/tests/management.py
268@@ -125,7 +125,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
269             email="joe@somewhere.org",
270             stdout=new_io
271         )
272-        u = User.objects.get(username="joe+admin@somewhere.org")
273+        u = User._default_manager.get(username="joe+admin@somewhere.org")
274         self.assertEqual(u.email, 'joe@somewhere.org')
275         self.assertFalse(u.has_usable_password())
276 
277@@ -145,7 +145,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
278         )
279         command_output = new_io.getvalue().strip()
280         self.assertEqual(command_output, 'Superuser created successfully.')
281-        u = CustomUser.objects.get(email="joe@somewhere.org")
282+        u = CustomUser._default_manager.get(email="joe@somewhere.org")
283         self.assertEqual(u.date_of_birth, date(1976, 4, 1))
284 
285         # created password should be unusable
286@@ -167,7 +167,7 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
287                 skip_validation=True
288             )
289 
290-        self.assertEqual(CustomUser.objects.count(), 0)
291+        self.assertEqual(CustomUser._default_manager.count(), 0)
292 
293 
294 class PermissionDuplicationTestCase(TestCase):
295diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py
296index da0e45a..8ac0599 100644
297--- a/django/contrib/auth/tests/models.py
298+++ b/django/contrib/auth/tests/models.py
299@@ -137,6 +137,6 @@ class IsActiveTestCase(TestCase):
300         user.is_active = False
301         # there should be no problem saving - but the attribute is not saved
302         user.save()
303-        user_fetched = UserModel.objects.get(pk=user.pk)
304+        user_fetched = UserModel._default_manager.get(pk=user.pk)
305         # the attribute is always true for newly retrieved instance
306         self.assertEqual(user_fetched.is_active, True)
307diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
308index 8514345..9d15346 100644
309--- a/django/contrib/auth/views.py
310+++ b/django/contrib/auth/views.py
311@@ -200,7 +200,7 @@ def password_reset_confirm(request, uidb36=None, token=None,
312         post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete')
313     try:
314         uid_int = base36_to_int(uidb36)
315-        user = UserModel.objects.get(pk=uid_int)
316+        user = UserModel._default_manager.get(pk=uid_int)
317     except (ValueError, OverflowError, UserModel.DoesNotExist):
318         user = None
319