Changeset 1440
- Timestamp:
- 11/26/05 01:20:07 (4 years ago)
- Files:
-
- django/trunk/django/views/auth/login.py (modified) (2 diffs)
- django/trunk/django/views/decorators/auth.py (modified) (2 diffs)
- django/trunk/docs/authentication.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/views/auth/login.py
r867 r1440 7 7 8 8 REDIRECT_FIELD_NAME = 'next' 9 LOGIN_URL = '/accounts/login/' 9 10 10 11 def login(request): … … 40 41 return HttpResponseRedirect(next_page or request.path) 41 42 42 def logout_then_login(request ):43 def logout_then_login(request, login_url=LOGIN_URL): 43 44 "Logs out the user if he is logged in. Then redirects to the log-in page." 44 return logout(request, '/accounts/login/')45 return logout(request, login_url) 45 46 46 def redirect_to_login(next ):47 def redirect_to_login(next, login_url=LOGIN_URL): 47 48 "Redirects the user to the login page, passing the given 'next' page" 48 return HttpResponseRedirect(' /accounts/login/?%s=%s' % (REDIRECT_FIELD_NAME, next))49 return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next)) django/trunk/django/views/decorators/auth.py
r1004 r1440 1 def user_passes_test(test_func): 1 from django.views.auth import login 2 3 def user_passes_test(test_func, login_url=login.LOGIN_URL): 2 4 """ 3 5 Decorator for views that checks that the user passes the given test, … … 7 9 def _dec(view_func): 8 10 def _checklogin(request, *args, **kwargs): 9 from django.views.auth.login import redirect_to_login10 11 if test_func(request.user): 11 12 return view_func(request, *args, **kwargs) 12 return redirect_to_login(request.path)13 return login.redirect_to_login(request.path, login_url) 13 14 return _checklogin 14 15 return _dec django/trunk/docs/authentication.txt
r1439 r1440 315 315 is not anonymous. 316 316 317 **New in the Django development version**: ``user_passes_test()`` takes an 318 optional ``login_url`` argument, which lets you specify the URL for your login 319 page (``/accounts/login/`` by default). 320 321 Example in Python 2.3 syntax:: 322 323 from django.views.decorators.auth import user_passes_test 324 325 def my_view(request): 326 # ... 327 my_view = user_passes_test(lambda u: u.has_perm('polls.can_vote'), login_url='/login/')(my_view) 328 329 Example in Python 2.4 syntax:: 330 331 from django.views.decorators.auth import user_passes_test 332 333 @user_passes_test(lambda u: u.has_perm('polls.can_vote'), login_url='/login/') 334 def my_view(request): 335 # ... 336 317 337 Limiting access to generic views 318 338 --------------------------------
