diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2016-04-02 13:18:26 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-09 14:54:18 -0400 |
| commit | c1aec0feda73ede09503192a66f973598aef901d (patch) | |
| tree | f1e4c09f3e98177cfe78cc9039b300f8984e7aed /docs/topics | |
| parent | c16b9dd8e0ae757616e9accbaffecc521191ee98 (diff) | |
Fixed #25847 -- Made User.is_(anonymous|authenticated) properties.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/auth/customizing.txt | 38 | ||||
| -rw-r--r-- | docs/topics/auth/default.txt | 12 | ||||
| -rw-r--r-- | docs/topics/cache.txt | 2 | ||||
| -rw-r--r-- | docs/topics/class-based-views/mixins.txt | 6 |
4 files changed, 36 insertions, 22 deletions
diff --git a/docs/topics/auth/customizing.txt b/docs/topics/auth/customizing.txt index 271d7f52f7..68ca0e7f55 100644 --- a/docs/topics/auth/customizing.txt +++ b/docs/topics/auth/customizing.txt @@ -603,7 +603,7 @@ password resets. You must then provide some key implementation details: raised a deprecation warning in older versions and is no longer supported in Django 1.9). -The following methods are available on any subclass of +The following attributes and methods are available on any subclass of :class:`~django.contrib.auth.models.AbstractBaseUser`: .. class:: models.AbstractBaseUser @@ -612,20 +612,34 @@ The following methods are available on any subclass of Returns the value of the field nominated by ``USERNAME_FIELD``. - .. method:: models.AbstractBaseUser.is_anonymous() + .. attribute:: models.AbstractBaseUser.is_authenticated - Always returns ``False``. This is a way of differentiating - from :class:`~django.contrib.auth.models.AnonymousUser` objects. - Generally, you should prefer using - :meth:`~django.contrib.auth.models.AbstractBaseUser.is_authenticated()` to this - method. + Read-only attribute which is always ``True`` (as opposed to + ``AnonymousUser.is_authenticated`` which is always ``False``). + This is a way to tell if the user has been authenticated. This does not + imply any permissions and doesn't check if the user is active or has + a valid session. Even though normally you will check this attribute on + ``request.user`` to find out whether it has been populated by the + :class:`~django.contrib.auth.middleware.AuthenticationMiddleware` + (representing the currently logged-in user), you should know this + attribute is ``True`` for any :class:`~models.User` instance. - .. method:: models.AbstractBaseUser.is_authenticated() + .. versionchanged:: 1.10 - Always returns ``True``. This is a way to tell if the user has been - authenticated. This does not imply any permissions, and doesn't check - if the user is active - it only indicates that the user has provided a - valid username and password. + In older versions, this was a method. Backwards-compatibility + support for using it as a method will be removed in Django 2.0. + + .. attribute:: models.AbstractBaseUser.is_anonymous + + Read-only attribute which is always ``False``. This is a way of + differentiating :class:`~models.User` and :class:`~models.AnonymousUser` + objects. Generally, you should prefer using + :attr:`~models.User.is_authenticated` to this attribute. + + .. versionchanged:: 1.10 + + In older versions, this was a method. Backwards-compatibility + support for using it as a method will be removed in Django 2.0. .. method:: models.AbstractBaseUser.set_password(raw_password) diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt index 72205740d5..4c8d44a0cd 100644 --- a/docs/topics/auth/default.txt +++ b/docs/topics/auth/default.txt @@ -306,9 +306,9 @@ of :class:`~django.contrib.auth.models.AnonymousUser`, otherwise it will be an instance of :class:`~django.contrib.auth.models.User`. You can tell them apart with -:meth:`~django.contrib.auth.models.User.is_authenticated()`, like so:: +:attr:`~django.contrib.auth.models.User.is_authenticated`, like so:: - if request.user.is_authenticated(): + if request.user.is_authenticated: # Do something for authenticated users. ... else: @@ -421,15 +421,15 @@ The raw way ~~~~~~~~~~~ The simple, raw way to limit access to pages is to check -:meth:`request.user.is_authenticated() -<django.contrib.auth.models.User.is_authenticated()>` and either redirect to a +:attr:`request.user.is_authenticated +<django.contrib.auth.models.User.is_authenticated>` and either redirect to a login page:: from django.conf import settings from django.shortcuts import redirect def my_view(request): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path)) # ... @@ -438,7 +438,7 @@ login page:: from django.shortcuts import render def my_view(request): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return render(request, 'myapp/login_error.html') # ... diff --git a/docs/topics/cache.txt b/docs/topics/cache.txt index 4cfffeeecf..b0bf37c94c 100644 --- a/docs/topics/cache.txt +++ b/docs/topics/cache.txt @@ -1170,7 +1170,7 @@ decorator):: @vary_on_cookie def list_blog_entries_view(request): - if request.user.is_anonymous(): + if request.user.is_anonymous: response = render_only_public_entries() patch_cache_control(response, public=True) else: diff --git a/docs/topics/class-based-views/mixins.txt b/docs/topics/class-based-views/mixins.txt index e53a8599e4..a5bb290d2b 100644 --- a/docs/topics/class-based-views/mixins.txt +++ b/docs/topics/class-based-views/mixins.txt @@ -235,7 +235,7 @@ We'll demonstrate this with the ``Author`` model we used in the model = Author def post(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden() # Look up the author we're interested in. @@ -466,7 +466,7 @@ Our new ``AuthorDetail`` looks like this:: return context def post(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden() self.object = self.get_object() form = self.get_form() @@ -552,7 +552,7 @@ template as ``AuthorDisplay`` is using on ``GET``:: model = Author def post(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseForbidden() self.object = self.get_object() return super(AuthorInterest, self).post(request, *args, **kwargs) |
