Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13304 -- Updated auth decorators so they can be used with call…

…able classes. Thanks to Horst Gutmann for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12938 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 056c940f0d723eb66fc06b43c28a743c84d54b3b 1 parent 736b751
Russell Keith-Magee authored April 09, 2010
3  django/contrib/auth/decorators.py
@@ -5,6 +5,7 @@
5 5
 
6 6
 from django.contrib.auth import REDIRECT_FIELD_NAME
7 7
 from django.http import HttpResponseRedirect
  8
+from django.utils.decorators import available_attrs
8 9
 from django.utils.http import urlquote
9 10
 
10 11
 
@@ -25,7 +26,7 @@ def _wrapped_view(request, *args, **kwargs):
25 26
             path = urlquote(request.get_full_path())
26 27
             tup = login_url, redirect_field_name, path
27 28
             return HttpResponseRedirect('%s?%s=%s' % tup)
28  
-        return wraps(view_func)(_wrapped_view)
  29
+        return wraps(view_func, assigned=available_attrs(view_func))(_wrapped_view)
29 30
     return decorator
30 31
 
31 32
 
9  django/contrib/auth/tests/__init__.py
... ...
@@ -1,12 +1,13 @@
  1
+from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
1 2
 from django.contrib.auth.tests.basic import BASIC_TESTS
2  
-from django.contrib.auth.tests.views \
3  
-        import PasswordResetTest, ChangePasswordTest, LoginTest, LogoutTest
  3
+from django.contrib.auth.tests.decorators import LoginRequiredTestCase
4 4
 from django.contrib.auth.tests.forms import FORM_TESTS
5 5
 from django.contrib.auth.tests.remote_user \
6 6
         import RemoteUserTest, RemoteUserNoCreateTest, RemoteUserCustomTest
7  
-from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
8  
-from django.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS
9 7
 from django.contrib.auth.tests.models import ProfileTestCase
  8
+from django.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS
  9
+from django.contrib.auth.tests.views \
  10
+        import PasswordResetTest, ChangePasswordTest, LoginTest, LogoutTest
10 11
 
11 12
 # The password for the fixture data users is 'password'
12 13
 
25  django/contrib/auth/tests/decorators.py
... ...
@@ -0,0 +1,25 @@
  1
+from unittest import TestCase
  2
+
  3
+from django.contrib.auth.decorators import login_required
  4
+
  5
+
  6
+class LoginRequiredTestCase(TestCase):
  7
+    """
  8
+    Tests the login_required decorators
  9
+    """
  10
+    def testCallable(self):
  11
+        """
  12
+        Check that login_required is assignable to callable objects.
  13
+        """
  14
+        class CallableView(object):
  15
+            def __call__(self, *args, **kwargs):
  16
+                pass
  17
+        login_required(CallableView())
  18
+        
  19
+    def testView(self):
  20
+        """
  21
+        Check that login_required is assignable to normal views.
  22
+        """
  23
+        def normal_view(request):
  24
+            pass
  25
+        login_required(normal_view)

0 notes on commit 056c940

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