Ticket #16611: auth.diff
File auth.diff, 3.4 KB (added by , 13 years ago) |
---|
-
docs/topics/auth.txt
308 308 * ``o``, ``O``, and ``0`` (uppercase letter o, lowercase letter o, 309 309 and zero) 310 310 311 .. method:: models.UserManager.active() 312 313 Returns ``QuerySet`` containing only active users (i.e. those, which have :attr:`~models.User.is_active` set to ``True``). 314 315 .. method:: models.UserManager.inactive() 316 317 Returns ``QuerySet`` containing only inactive users (i.e. those, which have :attr:`~models.User.is_active` set to ``False``). 318 311 319 Basic usage 312 320 ----------- 313 321 -
django/contrib/auth/tests/__init__.py
10 10 from django.contrib.auth.tests.remote_user import (RemoteUserTest, 11 11 RemoteUserNoCreateTest, RemoteUserCustomTest) 12 12 from django.contrib.auth.tests.management import GetDefaultUsernameTestCase 13 from django.contrib.auth.tests.models import ProfileTestCase 13 from django.contrib.auth.tests.models import ProfileTestCase, UserManagerTestCase 14 14 from django.contrib.auth.tests.signals import SignalTestCase 15 15 from django.contrib.auth.tests.tokens import TokenGeneratorTest 16 16 from django.contrib.auth.tests.views import (PasswordResetTest, -
django/contrib/auth/tests/models.py
33 33 # module that doesn't exist 34 34 settings.AUTH_PROFILE_MODULE = 'foo.bar' 35 35 self.assertRaises(SiteProfileNotAvailable, user.get_profile) 36 37 38 class UserManagerTestCase(TestCase): 39 def setUp(self): 40 User.objects.create_user('active1', 'active1@example.com', 'active1') 41 User.objects.create_user('active2', 'active2@example.com', 'active2') 42 43 User.objects.create_user('inactive1', 'inactive1@example.com', 'inactive1') 44 User.objects.create_user('inactive2', 'inactive2@example.com', 'inactive2') 45 User.objects.create_user('inactive3', 'inactive3@example.com', 'inactive3') 46 47 User.objects.filter(username__startswith='inactive').update(is_active=False) 48 49 def test_active_inactive_methods(self): 50 active_usernames = list(User.objects.active().order_by('username').values_list('username', flat=True)) 51 self.assertEqual([u'active1', u'active2'], active_usernames) 52 53 inactive_usernames = list(User.objects.inactive().order_by('username').values_list('username', flat=True)) 54 self.assertEqual([u'inactive1', u'inactive2', u'inactive3'], inactive_usernames) -
django/contrib/auth/models.py
128 128 # that look like it -- just to avoid confusion. 129 129 return get_random_string(length, allowed_chars) 130 130 131 def active(self): 132 return self.filter(is_active=True) 131 133 134 def inactive(self): 135 return self.filter(is_active=False) 136 137 132 138 # A few helper functions for common logic between User and AnonymousUser. 133 139 def _user_get_all_permissions(user, obj): 134 140 permissions = set()