Ticket #13304: django12-authdecorators-callable.diff

File django12-authdecorators-callable.diff, 2.0 KB (added by Horst Gutmann <horst@…>, 14 years ago)
  • django/contrib/auth/decorators.py

     
    55
    66from django.contrib.auth import REDIRECT_FIELD_NAME
    77from django.http import HttpResponseRedirect
     8from django.utils.decorators import available_attrs
    89from django.utils.http import urlquote
    910
    1011
     
    2526            path = urlquote(request.get_full_path())
    2627            tup = login_url, redirect_field_name, path
    2728            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)
    2930    return decorator
    3031
    3132
  • tests/regressiontests/auth_decorators/tests.py

     
     1from unittest import TestCase
     2
     3from django.contrib.auth.decorators import login_required
     4
     5
     6class 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)
     26 No newline at end of file
Back to Top