Ticket #19596: ticket19596.diff

File ticket19596.diff, 14.5 KB (added by apollo13, 3 years ago)
  • django/contrib/auth/backends.py

    diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
    index db99c94..703fd25 100644
    a b class ModelBackend(object): 
    1313    def authenticate(self, username=None, password=None):
    1414        try:
    1515            UserModel = get_user_model()
    16             user = UserModel.objects.get_by_natural_key(username)
     16            user = UserModel._default_manager.get_by_natural_key(username)
    1717            if user.check_password(password):
    1818                return user
    1919        except UserModel.DoesNotExist:
    class ModelBackend(object): 
    6464    def get_user(self, user_id):
    6565        try:
    6666            UserModel = get_user_model()
    67             return UserModel.objects.get(pk=user_id)
     67            return UserModel._default_manager.get(pk=user_id)
    6868        except UserModel.DoesNotExist:
    6969            return None
    7070
  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index 8529112..cbce8ad 100644
    a b class UserCreationForm(forms.ModelForm): 
    8989        # but it sets a nicer error message than the ORM. See #13147.
    9090        username = self.cleaned_data["username"]
    9191        try:
    92             User.objects.get(username=username)
     92            User._default_manager.get(username=username)
    9393        except User.DoesNotExist:
    9494            return username
    9595        raise forms.ValidationError(self.error_messages['duplicate_username'])
    class PasswordResetForm(forms.Form): 
    217217        """
    218218        UserModel = get_user_model()
    219219        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)
    221221        if not len(self.users_cache):
    222222            raise forms.ValidationError(self.error_messages['unknown'])
    223223        if not any(user.is_active for user in self.users_cache):
  • django/contrib/auth/handlers/modwsgi.py

    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): 
    1818
    1919    try:
    2020        try:
    21             user = UserModel.objects.get_by_natural_key(username)
     21            user = UserModel._default_manager.get_by_natural_key(username)
    2222        except UserModel.DoesNotExist:
    2323            return None
    2424        if not user.is_active:
    def groups_for_user(environ, username): 
    3737
    3838    try:
    3939        try:
    40             user = UserModel.objects.get_by_natural_key(username)
     40            user = UserModel._default_manager.get_by_natural_key(username)
    4141        except UserModel.DoesNotExist:
    4242            return []
    4343        try:
  • django/contrib/auth/management/__init__.py

    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): 
    174174    # Don't return the default username if it is already taken.
    175175    if check_db and default_username:
    176176        try:
    177             auth_app.User.objects.get(username=default_username)
     177            auth_app.User._default_manager.get(username=default_username)
    178178        except auth_app.User.DoesNotExist:
    179179            pass
    180180        else:
  • django/contrib/auth/management/commands/changepassword.py

    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): 
    3333        UserModel = get_user_model()
    3434
    3535        try:
    36             u = UserModel.objects.using(options.get('database')).get(**{
     36            u = UserModel._default_manager.using(options.get('database')).get(**{
    3737                    UserModel.USERNAME_FIELD: username
    3838                })
    3939        except UserModel.DoesNotExist:
  • django/contrib/auth/management/commands/createsuperuser.py

    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): 
    9595                        username = None
    9696                        continue
    9797                    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)
    9999                    except self.UserModel.DoesNotExist:
    100100                        pass
    101101                    else:
    class Command(BaseCommand): 
    134134
    135135        user_data[self.UserModel.USERNAME_FIELD] = username
    136136        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)
    138138        if verbosity >= 1:
    139139            self.stdout.write("Superuser created successfully.")
  • django/contrib/auth/tests/auth_backends.py

    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): 
    3434        ContentType.objects.clear_cache()
    3535
    3636    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)
    3838        self.assertEqual(user.has_perm('auth.test'), False)
    3939        user.is_staff = True
    4040        user.save()
    class BaseModelBackendTest(object): 
    5353        self.assertEqual(user.has_perm('auth.test'), False)
    5454
    5555    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)
    5757        content_type = ContentType.objects.get_for_model(Group)
    5858        perm = Permission.objects.create(name='test', content_type=content_type, codename='test')
    5959        user.user_permissions.add(perm)
    6060        user.save()
    6161
    6262        # 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)
    6464        self.assertEqual(user.get_all_permissions() == set(['auth.test']), True)
    6565        self.assertEqual(user.get_group_permissions(), set([]))
    6666        self.assertEqual(user.has_module_perms('Group'), False)
    class BaseModelBackendTest(object): 
    7171        perm = Permission.objects.create(name='test3', content_type=content_type, codename='test3')
    7272        user.user_permissions.add(perm)
    7373        user.save()
    74         user = self.UserModel.objects.get(pk=self.user.pk)
     74        user = self.UserModel._default_manager.get(pk=self.user.pk)
    7575        self.assertEqual(user.get_all_permissions(), set(['auth.test2', 'auth.test', 'auth.test3']))
    7676        self.assertEqual(user.has_perm('test'), False)
    7777        self.assertEqual(user.has_perm('auth.test'), True)
    class BaseModelBackendTest(object): 
    8181        group.permissions.add(perm)
    8282        group.save()
    8383        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)
    8585        exp = set(['auth.test2', 'auth.test', 'auth.test3', 'auth.test_group'])
    8686        self.assertEqual(user.get_all_permissions(), exp)
    8787        self.assertEqual(user.get_group_permissions(), set(['auth.test_group']))
    class BaseModelBackendTest(object): 
    9393
    9494    def test_has_no_object_perm(self):
    9595        """Regressiontest for #12462"""
    96         user = self.UserModel.objects.get(pk=self.user.pk)
     96        user = self.UserModel._default_manager.get(pk=self.user.pk)
    9797        content_type = ContentType.objects.get_for_model(Group)
    9898        perm = Permission.objects.create(name='test', content_type=content_type, codename='test')
    9999        user.user_permissions.add(perm)
    class BaseModelBackendTest(object): 
    106106
    107107    def test_get_all_superuser_permissions(self):
    108108        "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)
    110110        self.assertEqual(len(user.get_all_permissions()), len(Permission.objects.all()))
    111111
    112112
    class ExtensionUserModelBackendTest(BaseModelBackendTest, TestCase): 
    151151    UserModel = ExtensionUser
    152152
    153153    def create_users(self):
    154         self.user = ExtensionUser.objects.create_user(
     154        self.user = ExtensionUser._default_manager.create_user(
    155155            username='test',
    156156            email='test@example.com',
    157157            password='test',
    158158            date_of_birth=date(2006, 4, 25)
    159159        )
    160         self.superuser = ExtensionUser.objects.create_superuser(
     160        self.superuser = ExtensionUser._default_manager.create_superuser(
    161161            username='test2',
    162162            email='test2@example.com',
    163163            password='test',
    class CustomPermissionsUserModelBackendTest(BaseModelBackendTest, TestCase): 
    178178    UserModel = CustomPermissionsUser
    179179
    180180    def create_users(self):
    181         self.user = CustomPermissionsUser.objects.create_user(
     181        self.user = CustomPermissionsUser._default_manager.create_user(
    182182            email='test@example.com',
    183183            password='test',
    184184            date_of_birth=date(2006, 4, 25)
    185185        )
    186         self.superuser = CustomPermissionsUser.objects.create_superuser(
     186        self.superuser = CustomPermissionsUser._default_manager.create_superuser(
    187187            email='test2@example.com',
    188188            password='test',
    189189            date_of_birth=date(1976, 11, 8)
  • django/contrib/auth/tests/custom_user.py

    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): 
    4242    is_admin = models.BooleanField(default=False)
    4343    date_of_birth = models.DateField()
    4444
    45     objects = CustomUserManager()
     45    custom_objects = CustomUserManager()
    4646
    4747    USERNAME_FIELD = 'email'
    4848    REQUIRED_FIELDS = ['date_of_birth']
    class CustomUser(AbstractBaseUser): 
    8888class ExtensionUser(AbstractUser):
    8989    date_of_birth = models.DateField()
    9090
    91     objects = UserManager()
     91    custom_objects = UserManager()
    9292
    9393    REQUIRED_FIELDS = AbstractUser.REQUIRED_FIELDS + ['date_of_birth']
    9494
    class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin): 
    112112    email = models.EmailField(verbose_name='email address', max_length=255, unique=True)
    113113    date_of_birth = models.DateField()
    114114
    115     objects = CustomPermissionsUserManager()
     115    custom_objects = CustomPermissionsUserManager()
    116116
    117117    USERNAME_FIELD = 'email'
    118118    REQUIRED_FIELDS = ['date_of_birth']
    class IsActiveTestUser1(AbstractBaseUser): 
    136136    """
    137137    username = models.CharField(max_length=30, unique=True)
    138138
    139     objects = BaseUserManager()
     139    custom_objects = BaseUserManager()
    140140
    141141    USERNAME_FIELD = 'username'
    142142
  • django/contrib/auth/tests/handlers.py

    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): 
    4242        with custom user installed
    4343        """
    4444
    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')
    4646
    4747        # User not in database
    4848        self.assertTrue(check_password({}, 'unknown', '') is None)
  • django/contrib/auth/tests/management.py

    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): 
    125125            email="joe@somewhere.org",
    126126            stdout=new_io
    127127        )
    128         u = User.objects.get(username="joe+admin@somewhere.org")
     128        u = User._default_manager.get(username="joe+admin@somewhere.org")
    129129        self.assertEqual(u.email, 'joe@somewhere.org')
    130130        self.assertFalse(u.has_usable_password())
    131131
    class CreatesuperuserManagementCommandTestCase(TestCase): 
    145145        )
    146146        command_output = new_io.getvalue().strip()
    147147        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")
    149149        self.assertEqual(u.date_of_birth, date(1976, 4, 1))
    150150
    151151        # created password should be unusable
    class CreatesuperuserManagementCommandTestCase(TestCase): 
    167167                skip_validation=True
    168168            )
    169169
    170         self.assertEqual(CustomUser.objects.count(), 0)
     170        self.assertEqual(CustomUser._default_manager.count(), 0)
    171171
    172172
    173173class PermissionDuplicationTestCase(TestCase):
  • django/contrib/auth/tests/models.py

    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): 
    137137        user.is_active = False
    138138        # there should be no problem saving - but the attribute is not saved
    139139        user.save()
    140         user_fetched = UserModel.objects.get(pk=user.pk)
     140        user_fetched = UserModel._default_manager.get(pk=user.pk)
    141141        # the attribute is always true for newly retrieved instance
    142142        self.assertEqual(user_fetched.is_active, True)
  • django/contrib/auth/views.py

    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, 
    200200        post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete')
    201201    try:
    202202        uid_int = base36_to_int(uidb36)
    203         user = UserModel.objects.get(pk=uid_int)
     203        user = UserModel._default_manager.get(pk=uid_int)
    204204    except (ValueError, OverflowError, UserModel.DoesNotExist):
    205205        user = None
    206206
Back to Top