Ticket #16626: login_required.diff

File login_required.diff, 1.3 KB (added by szczav, 13 years ago)
  • django/views/generic/base.py

     
    44from django.template.response import TemplateResponse
    55from django.utils.log import getLogger
    66from django.utils.decorators import classonlymethod
     7from django.contrib.auth.decorators import login_required
    78
    89logger = getLogger('django.request')
    910
     
    1314    Intentionally simple parent class for all views. Only implements
    1415    dispatch-by-method and simple sanity checking.
    1516    """
     17    login_required = False
    1618
    1719    http_method_names = ['get', 'post', 'put', 'delete', 'head', 'options', 'trace']
    1820
     
    4345
    4446        def view(request, *args, **kwargs):
    4547            self = cls(**initkwargs)
     48
     49            @login_required
     50            def login_required_dispatch(request, *args, **kwargs):
     51                """
     52                Wrapper on dispatch method used for login_required decorator.
     53                """
     54                return self.dispatch(request, *args, **kwargs)
     55
     56            if self.login_required:
     57                return login_required_dispatch(request, *args, **kwargs)
    4658            return self.dispatch(request, *args, **kwargs)
    4759
    4860        # take name and docstring from class
Back to Top