Ticket #3032: anonymous-user-properties.2.diff

File anonymous-user-properties.2.diff, 3.0 KB (added by Ilya Semenov, 17 years ago)
  • django/db/models/manager.py

     
    111111        if instance != None:
    112112            raise AttributeError, "Manager isn't accessible via %s instances" % type.__name__
    113113        return self.manager
     114
     115class EmptyManager(Manager):
     116    def get_query_set(self):
     117        return self.get_empty_query_set()
  • django/contrib/auth/tests.py

     
    11"""
    2 >>> from models import User
     2>>> from models import User, AnonymousUser
    33>>> u = User.objects.create_user('testuser', 'test@example.com', 'testpw')
    44>>> u.has_usable_password()
    55True
     
    1616>>> u2 = User.objects.create_user('testuser2', 'test2@example.com')
    1717>>> u2.has_usable_password()
    1818False
     19>>> a = AnonymousUser()
     20>>> a.is_staff
     21False
     22>>> a.groups.all()
     23[]
     24>>> a.user_permissions.all()
     25[]
    1926"""
     27 No newline at end of file
  • django/contrib/auth/models.py

     
    11from django.core import validators
    22from django.core.exceptions import ImproperlyConfigured
    33from django.db import connection, models
     4from django.db.models.manager import EmptyManager
    45from django.contrib.contenttypes.models import ContentType
    56from django.utils.encoding import smart_str
    67from django.utils.translation import ugettext_lazy as _
     
    293294class AnonymousUser(object):
    294295    id = None
    295296    username = ''
     297    is_staff = False
     298    is_active = True
     299    is_superuser = False
     300    _groups = EmptyManager()
     301    _user_permissions = EmptyManager()
    296302
    297303    def __init__(self):
    298304        pass
     
    325331        raise NotImplementedError
    326332
    327333    def _get_groups(self):
    328         raise NotImplementedError
     334        return self._groups
    329335    groups = property(_get_groups)
    330336
    331337    def _get_user_permissions(self):
    332         raise NotImplementedError
     338        return self._user_permissions
    333339    user_permissions = property(_get_user_permissions)
    334340
    335341    def has_perm(self, perm):
  • docs/authentication.txt

     
    244244the ``django.contrib.auth.models.User`` interface, with these differences:
    245245
    246246    * ``id`` is always ``None``.
     247    * ``is_staff`` and ``is_superuser`` are always False
     248    * ``is_active`` is always True
     249    * ``groups`` and ``user_permissions`` are always empty
    247250    * ``is_anonymous()`` returns ``True`` instead of ``False``.
    248251    * ``is_authenticated()`` returns ``False`` instead of ``True``.
    249252    * ``has_perm()`` always returns ``False``.
Back to Top