web/lib/django/contrib/admin/views/decorators.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
     1 import base64
     1 import base64
     2 try:
     2 try:
     3     from functools import wraps
     3     from functools import wraps
     4 except ImportError:
     4 except ImportError:
     5     from django.utils.functional import wraps  # Python 2.3, 2.4 fallback.
     5     from django.utils.functional import wraps  # Python 2.4 fallback.
     6 
     6 
     7 from django import http, template
     7 from django import http, template
     8 from django.conf import settings
     8 from django.conf import settings
     9 from django.contrib.auth.models import User
     9 from django.contrib.auth.models import User
    10 from django.contrib.auth import authenticate, login
    10 from django.contrib.auth import authenticate, login
    26     """
    26     """
    27     Decorator for views that checks that the user is logged in and is a staff
    27     Decorator for views that checks that the user is logged in and is a staff
    28     member, displaying the login page if necessary.
    28     member, displaying the login page if necessary.
    29     """
    29     """
    30     def _checklogin(request, *args, **kwargs):
    30     def _checklogin(request, *args, **kwargs):
    31         if request.user.is_authenticated() and request.user.is_staff:
    31         if request.user.is_active and request.user.is_staff:
    32             # The user is valid. Continue to the admin page.
    32             # The user is valid. Continue to the admin page.
    33             return view_func(request, *args, **kwargs)
    33             return view_func(request, *args, **kwargs)
    34 
    34 
    35         assert hasattr(request, 'session'), "The Django admin requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
    35         assert hasattr(request, 'session'), "The Django admin requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
    36 
    36