Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #684 -- Fixed login_required and user_passes_test decorators. T…

…hanks, rjwittams

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1004 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 43ad69e24e556c26cdefd96f84a8d06e086ff854 1 parent 17f6226
Adrian Holovaty authored October 23, 2005

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. 21  django/views/decorators/auth.py
21  django/views/decorators/auth.py
... ...
@@ -1,19 +1,22 @@
1  
-def user_passes_test(view_func, test_func):
  1
+def user_passes_test(test_func):
2 2
     """
3 3
     Decorator for views that checks that the user passes the given test,
4 4
     redirecting to the log-in page if necessary. The test should be a callable
5 5
     that takes the user object and returns True if the user passes.
6 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
  7
+    def _dec(view_func):
  8
+        def _checklogin(request, *args, **kwargs):
  9
+            from django.views.auth.login import redirect_to_login
  10
+            if test_func(request.user):
  11
+                return view_func(request, *args, **kwargs)
  12
+            return redirect_to_login(request.path)
  13
+        return _checklogin
  14
+    return _dec
13 15
 
14  
-def login_required(view_func):
  16
+login_required = user_passes_test(lambda u: not u.is_anonymous())
  17
+login_required.__doc__ = (
15 18
     """
16 19
     Decorator for views that checks that the user is logged in, redirecting
17 20
     to the log-in page if necessary.
18 21
     """
19  
-    return user_passes_test(lambda u: not u.is_anonymous())
  22
+    )

0 notes on commit 43ad69e

Please sign in to comment.
Something went wrong with that request. Please try again.