diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-10-23 22:42:44 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-10-23 22:42:44 +0000 |
| commit | 43ad69e24e556c26cdefd96f84a8d06e086ff854 (patch) | |
| tree | ec87d499f190b692e9892be89c0d5f077e7a7985 | |
| parent | 17f62269c2168549b76ee6204a1423a6e6f4e5f5 (diff) | |
Fixed #684 -- Fixed login_required and user_passes_test decorators. Thanks, rjwittams
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1004 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/views/decorators/auth.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/django/views/decorators/auth.py b/django/views/decorators/auth.py index f543a6aa48..a5a28bb0b2 100644 --- a/django/views/decorators/auth.py +++ b/django/views/decorators/auth.py @@ -1,19 +1,22 @@ -def user_passes_test(view_func, test_func): +def user_passes_test(test_func): """ Decorator for views that checks that the user passes the given test, redirecting to the log-in page if necessary. The test should be a callable that takes the user object and returns True if the user passes. """ - from django.views.auth.login import redirect_to_login - def _checklogin(request, *args, **kwargs): - if test_func(request.user): - return view_func(request, *args, **kwargs) - return redirect_to_login(request.path) - return _checklogin + def _dec(view_func): + def _checklogin(request, *args, **kwargs): + from django.views.auth.login import redirect_to_login + if test_func(request.user): + return view_func(request, *args, **kwargs) + return redirect_to_login(request.path) + return _checklogin + return _dec -def login_required(view_func): +login_required = user_passes_test(lambda u: not u.is_anonymous()) +login_required.__doc__ = ( """ Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary. """ - return user_passes_test(lambda u: not u.is_anonymous()) + ) |
