Ticket #3032: anonymous-user-properties.diff

File anonymous-user-properties.diff, 2.3 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/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