Hello site
[auf_framonde.git] / eggs / Django-1.4.5-py2.7.egg / django / contrib / admin / views / decorators.py
CommitLineData
01b54c21
MN
1from functools import wraps
2from django.utils.translation import ugettext as _
3from django.contrib.admin.forms import AdminAuthenticationForm
4from django.contrib.auth.views import login
5from django.contrib.auth import REDIRECT_FIELD_NAME
6
7def staff_member_required(view_func):
8 """
9 Decorator for views that checks that the user is logged in and is a staff
10 member, displaying the login page if necessary.
11 """
12 @wraps(view_func)
13 def _checklogin(request, *args, **kwargs):
14 if request.user.is_active and request.user.is_staff:
15 # The user is valid. Continue to the admin page.
16 return view_func(request, *args, **kwargs)
17
18 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'."
19 defaults = {
20 'template_name': 'admin/login.html',
21 'authentication_form': AdminAuthenticationForm,
22 'extra_context': {
23 'title': _('Log in'),
24 'app_path': request.get_full_path(),
25 REDIRECT_FIELD_NAME: request.get_full_path(),
26 },
27 }
28 return login(request, **defaults)
29 return _checklogin