Fixed #848 -- Made auth docs more clear on permission handling.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1302 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-20 16:35:44 +00:00
parent 58f95c3a6a
commit cd01d6d381
1 changed files with 15 additions and 6 deletions

View File

@ -49,10 +49,10 @@ Fields
and can contain any character. and can contain any character.
* ``is_staff`` -- Boolean. Designates whether this user can access the * ``is_staff`` -- Boolean. Designates whether this user can access the
admin site. admin site.
* ``is_active`` -- Boolean. Designates whether this user account is valid. * ``is_active`` -- Boolean. Designates whether this user can log into the
Set this to ``False`` instead of deleting accounts. Django admin. Set this to ``False`` instead of deleting accounts.
* ``is_superuser`` -- Boolean. Designates whether this user has permission * ``is_superuser`` -- Boolean. Designates that this user has all permissions
to do anything (according to the permission system). without explicitly assigning them.
* ``last_login`` -- A datetime of the user's last login. Is set to the * ``last_login`` -- A datetime of the user's last login. Is set to the
current date/time by default. current date/time by default.
* ``date_joined`` -- A datetime designating when the account was created. * ``date_joined`` -- A datetime designating when the account was created.
@ -93,10 +93,11 @@ methods:
the user has, both through group and user permissions. the user has, both through group and user permissions.
* ``has_perm(perm)`` -- Returns ``True`` if the user has the specified * ``has_perm(perm)`` -- Returns ``True`` if the user has the specified
permission. permission, where perm is in the format ``"package.codename"``.
* ``has_perms(perm_list)`` -- Returns ``True`` if the user has each of the * ``has_perms(perm_list)`` -- Returns ``True`` if the user has each of the
specified permissions. specified permissions, where each perm is in the format
``"package.codename"``.
* ``has_module_perms(package_name)`` -- Returns ``True`` if the user has * ``has_module_perms(package_name)`` -- Returns ``True`` if the user has
any permissions in the given package (the Django app label). any permissions in the given package (the Django app label).
@ -274,6 +275,14 @@ As a shortcut, you can use the convenient ``user_passes_test`` decorator::
from django.views.decorators.auth import user_passes_test from django.views.decorators.auth import user_passes_test
def my_view(request):
# ...
my_view = user_passes_test(my_view, lambda u: u.has_perm('polls.can_vote'))
Here's the same thing, using Python 2.4's decorator syntax::
from django.views.decorators.auth import user_passes_test
@user_passes_test(lambda u: u.has_perm('polls.can_vote')) @user_passes_test(lambda u: u.has_perm('polls.can_vote'))
def my_view(request): def my_view(request):
# ... # ...