Changeset 988
- Timestamp:
- 10/21/05 19:04:55 (3 years ago)
- Files:
-
- django/trunk/django/views/decorators/auth.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/views/decorators/auth.py
r3 r988 1 def user_passes_test(view_func, test_func): 2 """ 3 Decorator for views that checks that the user passes the given test, 4 redirecting to the log-in page if necessary. The test should be a callable 5 that takes the user object and returns True if the user passes. 6 """ 7 from django.views.auth.login import redirect_to_login 8 def _checklogin(request, *args, **kwargs): 9 if test_func(request.user): 10 return view_func(request, *args, **kwargs) 11 return redirect_to_login(request.path) 12 return _checklogin 13 1 14 def login_required(view_func): 2 15 """ … … 4 17 to the log-in page if necessary. 5 18 """ 6 from django.views.auth.login import redirect_to_login 7 def _checklogin(request, *args, **kwargs): 8 if request.user.is_anonymous(): 9 return redirect_to_login(request.path) 10 else: 11 return view_func(request, *args, **kwargs) 12 return _checklogin 19 return user_passes_test(lambda u: not u.is_anonymous())
