Django

Code

Changeset 3835

Show
Ignore:
Timestamp:
09/25/06 12:33:17 (2 years ago)
Author:
adrian
Message:

Fixed typos and improved documentation for permission_required decorator addition from [3779]

Files:

Legend:

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

    r3779 r3835  
    3030def permission_required(perm, login_url=LOGIN_URL): 
    3131    """ 
    32     Decorator for views that checks if a user has a particular permission 
    33     enabled, redirectiing to the log-in page if necessary. 
     32    Decorator for views that checks whether a user has a particular permission 
     33    enabled, redirecting to the log-in page if necessary. 
    3434    """ 
    3535    return user_passes_test(lambda u: u.has_perm(perm), login_url=login_url) 
  • django/trunk/docs/authentication.txt

    r3793 r3835  
    457457    my_view = user_passes_test(lambda u: u.has_perm('polls.can_vote'))(my_view) 
    458458 
    459 We are using this particular test as a relatively simple example, however be 
    460 aware that if you just want to test if a permission is available to a user, 
    461 you can use the ``permission_required()`` decorator described below
     459We're using this particular test as a relatively simple example. However, if 
     460you just want to test whether a permission is available to a user, you can use 
     461the ``permission_required()`` decorator, described later in this document
    462462 
    463463Here's the same thing, using Python 2.4's decorator syntax:: 
     
    496496~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    497497 
    498 Since checking whether a user has a particular permission available to them is a 
    499 relatively common operation, Django provides a shortcut for that particular 
    500 case: the ``permission_required()`` decorator. Using this decorator, the 
    501 earlier example can be written as:: 
     498**New in Django development version** 
     499 
     500It's a relatively common task to check whether a user has a particular 
     501permission. For that reason, Django provides a shortcut for that case: the 
     502``permission_required()`` decorator. Using this decorator, the earlier example 
     503can be written as:: 
    502504 
    503505    from django.contrib.auth.decorators import permission_required 
    504       
    505     def my_view(request): 
    506         # ... 
    507       
     506 
     507    def my_view(request): 
     508        # ... 
    508509    my_view = permission_required('polls.can_vote')(my_view) 
    509510 
    510511Note that ``permission_required()`` also takes an optional ``login_url`` 
    511 parameter. 
     512parameter. Example:: 
     513 
     514    from django.contrib.auth.decorators import permission_required 
     515 
     516    def my_view(request): 
     517        # ... 
     518    my_view = permission_required('polls.can_vote', login_url='/loginpage/')(my_view) 
     519 
     520As in the ``login_required`` decorator, ``login_url`` defaults to 
     521``'/accounts/login/'``. 
    512522 
    513523Limiting access to generic views 
     
    634644 
    635645    {% if user.is_authenticated %} 
    636         <p>Welcome, {{ user.username }}. Thanks for logging in.</p>     
     646        <p>Welcome, {{ user.username }}. Thanks for logging in.</p> 
    637647    {% else %} 
    638648        <p>Welcome, new user. Please log in.</p>