diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
index db99c94..703fd25 100644
a
|
b
|
class ModelBackend(object):
|
13 | 13 | def authenticate(self, username=None, password=None): |
14 | 14 | try: |
15 | 15 | UserModel = get_user_model() |
16 | | user = UserModel.objects.get_by_natural_key(username) |
| 16 | user = UserModel._default_manager.get_by_natural_key(username) |
17 | 17 | if user.check_password(password): |
18 | 18 | return user |
19 | 19 | except UserModel.DoesNotExist: |
… |
… |
class ModelBackend(object):
|
64 | 64 | def get_user(self, user_id): |
65 | 65 | try: |
66 | 66 | UserModel = get_user_model() |
67 | | return UserModel.objects.get(pk=user_id) |
| 67 | return UserModel._default_manager.get(pk=user_id) |
68 | 68 | except UserModel.DoesNotExist: |
69 | 69 | return None |
70 | 70 | |
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 8529112..cbce8ad 100644
a
|
b
|
class UserCreationForm(forms.ModelForm):
|
89 | 89 | # but it sets a nicer error message than the ORM. See #13147. |
90 | 90 | username = self.cleaned_data["username"] |
91 | 91 | try: |
92 | | User.objects.get(username=username) |
| 92 | User._default_manager.get(username=username) |
93 | 93 | except User.DoesNotExist: |
94 | 94 | return username |
95 | 95 | raise forms.ValidationError(self.error_messages['duplicate_username']) |
… |
… |
class PasswordResetForm(forms.Form):
|
217 | 217 | """ |
218 | 218 | UserModel = get_user_model() |
219 | 219 | email = self.cleaned_data["email"] |
220 | | self.users_cache = UserModel.objects.filter(email__iexact=email) |
| 220 | self.users_cache = UserModel._default_manager.filter(email__iexact=email) |
221 | 221 | if not len(self.users_cache): |
222 | 222 | raise forms.ValidationError(self.error_messages['unknown']) |
223 | 223 | if not any(user.is_active for user in self.users_cache): |
diff --git a/django/contrib/auth/handlers/modwsgi.py b/django/contrib/auth/handlers/modwsgi.py
index 5ee4d60..a26d621 100644
a
|
b
|
def check_password(environ, username, password):
|
18 | 18 | |
19 | 19 | try: |
20 | 20 | try: |
21 | | user = UserModel.objects.get_by_natural_key(username) |
| 21 | user = UserModel._default_manager.get_by_natural_key(username) |
22 | 22 | except UserModel.DoesNotExist: |
23 | 23 | return None |
24 | 24 | if not user.is_active: |
… |
… |
def groups_for_user(environ, username):
|
37 | 37 | |
38 | 38 | try: |
39 | 39 | try: |
40 | | user = UserModel.objects.get_by_natural_key(username) |
| 40 | user = UserModel._default_manager.get_by_natural_key(username) |
41 | 41 | except UserModel.DoesNotExist: |
42 | 42 | return [] |
43 | 43 | try: |
diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index ce5d57f..a77bba0 100644
a
|
b
|
def get_default_username(check_db=True):
|
174 | 174 | # Don't return the default username if it is already taken. |
175 | 175 | if check_db and default_username: |
176 | 176 | try: |
177 | | auth_app.User.objects.get(username=default_username) |
| 177 | auth_app.User._default_manager.get(username=default_username) |
178 | 178 | except auth_app.User.DoesNotExist: |
179 | 179 | pass |
180 | 180 | else: |
diff --git a/django/contrib/auth/management/commands/changepassword.py b/django/contrib/auth/management/commands/changepassword.py
index ff38836..3240b0f 100644
a
|
b
|
class Command(BaseCommand):
|
33 | 33 | UserModel = get_user_model() |
34 | 34 | |
35 | 35 | try: |
36 | | u = UserModel.objects.using(options.get('database')).get(**{ |
| 36 | u = UserModel._default_manager.using(options.get('database')).get(**{ |
37 | 37 | UserModel.USERNAME_FIELD: username |
38 | 38 | }) |
39 | 39 | except UserModel.DoesNotExist: |
diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py
index 216d56d..7b4764a 100644
a
|
b
|
class Command(BaseCommand):
|
95 | 95 | username = None |
96 | 96 | continue |
97 | 97 | try: |
98 | | self.UserModel.objects.db_manager(database).get_by_natural_key(username) |
| 98 | self.UserModel._default_manager.db_manager(database).get_by_natural_key(username) |
99 | 99 | except self.UserModel.DoesNotExist: |
100 | 100 | pass |
101 | 101 | else: |
… |
… |
class Command(BaseCommand):
|
134 | 134 | |
135 | 135 | user_data[self.UserModel.USERNAME_FIELD] = username |
136 | 136 | user_data['password'] = password |
137 | | self.UserModel.objects.db_manager(database).create_superuser(**user_data) |
| 137 | self.UserModel._default_manager.db_manager(database).create_superuser(**user_data) |
138 | 138 | if verbosity >= 1: |
139 | 139 | self.stdout.write("Superuser created successfully.") |
diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py
index 71f18d3..074374c 100644
a
|
b
|
class BaseModelBackendTest(object):
|
34 | 34 | ContentType.objects.clear_cache() |
35 | 35 | |
36 | 36 | def test_has_perm(self): |
37 | | user = self.UserModel.objects.get(pk=self.user.pk) |
| 37 | user = self.UserModel._default_manager.get(pk=self.user.pk) |
38 | 38 | self.assertEqual(user.has_perm('auth.test'), False) |
39 | 39 | user.is_staff = True |
40 | 40 | user.save() |
… |
… |
class BaseModelBackendTest(object):
|
53 | 53 | self.assertEqual(user.has_perm('auth.test'), False) |
54 | 54 | |
55 | 55 | def test_custom_perms(self): |
56 | | user = self.UserModel.objects.get(pk=self.user.pk) |
| 56 | user = self.UserModel._default_manager.get(pk=self.user.pk) |
57 | 57 | content_type = ContentType.objects.get_for_model(Group) |
58 | 58 | perm = Permission.objects.create(name='test', content_type=content_type, codename='test') |
59 | 59 | user.user_permissions.add(perm) |
60 | 60 | user.save() |
61 | 61 | |
62 | 62 | # reloading user to purge the _perm_cache |
63 | | user = self.UserModel.objects.get(pk=self.user.pk) |
| 63 | user = self.UserModel._default_manager.get(pk=self.user.pk) |
64 | 64 | self.assertEqual(user.get_all_permissions() == set(['auth.test']), True) |
65 | 65 | self.assertEqual(user.get_group_permissions(), set([])) |
66 | 66 | self.assertEqual(user.has_module_perms('Group'), False) |
… |
… |
class BaseModelBackendTest(object):
|
71 | 71 | perm = Permission.objects.create(name='test3', content_type=content_type, codename='test3') |
72 | 72 | user.user_permissions.add(perm) |
73 | 73 | user.save() |
74 | | user = self.UserModel.objects.get(pk=self.user.pk) |
| 74 | user = self.UserModel._default_manager.get(pk=self.user.pk) |
75 | 75 | self.assertEqual(user.get_all_permissions(), set(['auth.test2', 'auth.test', 'auth.test3'])) |
76 | 76 | self.assertEqual(user.has_perm('test'), False) |
77 | 77 | self.assertEqual(user.has_perm('auth.test'), True) |
… |
… |
class BaseModelBackendTest(object):
|
81 | 81 | group.permissions.add(perm) |
82 | 82 | group.save() |
83 | 83 | user.groups.add(group) |
84 | | user = self.UserModel.objects.get(pk=self.user.pk) |
| 84 | user = self.UserModel._default_manager.get(pk=self.user.pk) |
85 | 85 | exp = set(['auth.test2', 'auth.test', 'auth.test3', 'auth.test_group']) |
86 | 86 | self.assertEqual(user.get_all_permissions(), exp) |
87 | 87 | self.assertEqual(user.get_group_permissions(), set(['auth.test_group'])) |
… |
… |
class BaseModelBackendTest(object):
|
93 | 93 | |
94 | 94 | def test_has_no_object_perm(self): |
95 | 95 | """Regressiontest for #12462""" |
96 | | user = self.UserModel.objects.get(pk=self.user.pk) |
| 96 | user = self.UserModel._default_manager.get(pk=self.user.pk) |
97 | 97 | content_type = ContentType.objects.get_for_model(Group) |
98 | 98 | perm = Permission.objects.create(name='test', content_type=content_type, codename='test') |
99 | 99 | user.user_permissions.add(perm) |
… |
… |
class BaseModelBackendTest(object):
|
106 | 106 | |
107 | 107 | def test_get_all_superuser_permissions(self): |
108 | 108 | "A superuser has all permissions. Refs #14795" |
109 | | user = self.UserModel.objects.get(pk=self.superuser.pk) |
| 109 | user = self.UserModel._default_manager.get(pk=self.superuser.pk) |
110 | 110 | self.assertEqual(len(user.get_all_permissions()), len(Permission.objects.all())) |
111 | 111 | |
112 | 112 | |
… |
… |
class ExtensionUserModelBackendTest(BaseModelBackendTest, TestCase):
|
151 | 151 | UserModel = ExtensionUser |
152 | 152 | |
153 | 153 | def create_users(self): |
154 | | self.user = ExtensionUser.objects.create_user( |
| 154 | self.user = ExtensionUser._default_manager.create_user( |
155 | 155 | username='test', |
156 | 156 | email='test@example.com', |
157 | 157 | password='test', |
158 | 158 | date_of_birth=date(2006, 4, 25) |
159 | 159 | ) |
160 | | self.superuser = ExtensionUser.objects.create_superuser( |
| 160 | self.superuser = ExtensionUser._default_manager.create_superuser( |
161 | 161 | username='test2', |
162 | 162 | email='test2@example.com', |
163 | 163 | password='test', |
… |
… |
class CustomPermissionsUserModelBackendTest(BaseModelBackendTest, TestCase):
|
178 | 178 | UserModel = CustomPermissionsUser |
179 | 179 | |
180 | 180 | def create_users(self): |
181 | | self.user = CustomPermissionsUser.objects.create_user( |
| 181 | self.user = CustomPermissionsUser._default_manager.create_user( |
182 | 182 | email='test@example.com', |
183 | 183 | password='test', |
184 | 184 | date_of_birth=date(2006, 4, 25) |
185 | 185 | ) |
186 | | self.superuser = CustomPermissionsUser.objects.create_superuser( |
| 186 | self.superuser = CustomPermissionsUser._default_manager.create_superuser( |
187 | 187 | email='test2@example.com', |
188 | 188 | password='test', |
189 | 189 | date_of_birth=date(1976, 11, 8) |
diff --git a/django/contrib/auth/tests/custom_user.py b/django/contrib/auth/tests/custom_user.py
index 7e042e4..8cc57d4 100644
a
|
b
|
class CustomUser(AbstractBaseUser):
|
42 | 42 | is_admin = models.BooleanField(default=False) |
43 | 43 | date_of_birth = models.DateField() |
44 | 44 | |
45 | | objects = CustomUserManager() |
| 45 | custom_objects = CustomUserManager() |
46 | 46 | |
47 | 47 | USERNAME_FIELD = 'email' |
48 | 48 | REQUIRED_FIELDS = ['date_of_birth'] |
… |
… |
class CustomUser(AbstractBaseUser):
|
88 | 88 | class ExtensionUser(AbstractUser): |
89 | 89 | date_of_birth = models.DateField() |
90 | 90 | |
91 | | objects = UserManager() |
| 91 | custom_objects = UserManager() |
92 | 92 | |
93 | 93 | REQUIRED_FIELDS = AbstractUser.REQUIRED_FIELDS + ['date_of_birth'] |
94 | 94 | |
… |
… |
class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin):
|
112 | 112 | email = models.EmailField(verbose_name='email address', max_length=255, unique=True) |
113 | 113 | date_of_birth = models.DateField() |
114 | 114 | |
115 | | objects = CustomPermissionsUserManager() |
| 115 | custom_objects = CustomPermissionsUserManager() |
116 | 116 | |
117 | 117 | USERNAME_FIELD = 'email' |
118 | 118 | REQUIRED_FIELDS = ['date_of_birth'] |
… |
… |
class IsActiveTestUser1(AbstractBaseUser):
|
136 | 136 | """ |
137 | 137 | username = models.CharField(max_length=30, unique=True) |
138 | 138 | |
139 | | objects = BaseUserManager() |
| 139 | custom_objects = BaseUserManager() |
140 | 140 | |
141 | 141 | USERNAME_FIELD = 'username' |
142 | 142 | |
diff --git a/django/contrib/auth/tests/handlers.py b/django/contrib/auth/tests/handlers.py
index 04ab46f..41063aa 100644
a
|
b
|
class ModWsgiHandlerTestCase(TransactionTestCase):
|
42 | 42 | with custom user installed |
43 | 43 | """ |
44 | 44 | |
45 | | CustomUser.objects.create_user('test@example.com', '1990-01-01', 'test') |
| 45 | CustomUser._default_manager.create_user('test@example.com', '1990-01-01', 'test') |
46 | 46 | |
47 | 47 | # User not in database |
48 | 48 | self.assertTrue(check_password({}, 'unknown', '') is None) |
diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py
index 02939e3..42f14d6 100644
a
|
b
|
class CreatesuperuserManagementCommandTestCase(TestCase):
|
125 | 125 | email="joe@somewhere.org", |
126 | 126 | stdout=new_io |
127 | 127 | ) |
128 | | u = User.objects.get(username="joe+admin@somewhere.org") |
| 128 | u = User._default_manager.get(username="joe+admin@somewhere.org") |
129 | 129 | self.assertEqual(u.email, 'joe@somewhere.org') |
130 | 130 | self.assertFalse(u.has_usable_password()) |
131 | 131 | |
… |
… |
class CreatesuperuserManagementCommandTestCase(TestCase):
|
145 | 145 | ) |
146 | 146 | command_output = new_io.getvalue().strip() |
147 | 147 | self.assertEqual(command_output, 'Superuser created successfully.') |
148 | | u = CustomUser.objects.get(email="joe@somewhere.org") |
| 148 | u = CustomUser._default_manager.get(email="joe@somewhere.org") |
149 | 149 | self.assertEqual(u.date_of_birth, date(1976, 4, 1)) |
150 | 150 | |
151 | 151 | # created password should be unusable |
… |
… |
class CreatesuperuserManagementCommandTestCase(TestCase):
|
167 | 167 | skip_validation=True |
168 | 168 | ) |
169 | 169 | |
170 | | self.assertEqual(CustomUser.objects.count(), 0) |
| 170 | self.assertEqual(CustomUser._default_manager.count(), 0) |
171 | 171 | |
172 | 172 | |
173 | 173 | class PermissionDuplicationTestCase(TestCase): |
diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py
index da0e45a..8ac0599 100644
a
|
b
|
class IsActiveTestCase(TestCase):
|
137 | 137 | user.is_active = False |
138 | 138 | # there should be no problem saving - but the attribute is not saved |
139 | 139 | user.save() |
140 | | user_fetched = UserModel.objects.get(pk=user.pk) |
| 140 | user_fetched = UserModel._default_manager.get(pk=user.pk) |
141 | 141 | # the attribute is always true for newly retrieved instance |
142 | 142 | self.assertEqual(user_fetched.is_active, True) |
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index 8514345..9d15346 100644
a
|
b
|
def password_reset_confirm(request, uidb36=None, token=None,
|
200 | 200 | post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete') |
201 | 201 | try: |
202 | 202 | uid_int = base36_to_int(uidb36) |
203 | | user = UserModel.objects.get(pk=uid_int) |
| 203 | user = UserModel._default_manager.get(pk=uid_int) |
204 | 204 | except (ValueError, OverflowError, UserModel.DoesNotExist): |
205 | 205 | user = None |
206 | 206 | |