Django

Code

Changeset 6299

Show
Ignore:
Timestamp:
09/15/07 13:01:29 (1 year ago)
Author:
mtredinnick
Message:

Fixed #3032 -- Added some useful methods and attributes so that AnonymousUser? can proxy for a User a bit more logically. Patch from semenov.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/auth/models.py

    r5967 r6299  
    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 
     
    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): 
     
    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 
  • django/trunk/django/contrib/auth/tests.py

    r5876 r6299  
    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() 
     
    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""" 
  • django/trunk/django/db/models/manager.py

    r5823 r6299  
    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/trunk/docs/authentication.txt

    r6297 r6299  
    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``.