def staff_member_required(view_func):
 def _checklogin(request, *args, **kwargs):
  if (request.user.is_authenticated() and request.user.is_staff):
   return view_func(request, *args, **kwargs)
  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'."
  if (not request.POST.has_key(LOGIN_FORM_KEY)):
   if request.POST:
    message = _('Please log in again, because your session has expired.')
   else:
    message = ''
   return _display_login_form(request, message)
  if (not request.session.test_cookie_worked()):
   message = _("Looks like your browser isn't configured to accept cookies. Please enable cookies, reload this page, and try again.")
   return _display_login_form(request, message)
  username = request.POST.get('username', None)
  password = request.POST.get('password', None)
  user = authenticate(username=username, password=password)
  if (user is None):
   message = ERROR_MESSAGE
   if ('@' in username):
    try:
     user = User.objects.get(email=username)
    except User.DoesNotExist:
     message = _("Usernames cannot contain the '@' character.")
    else:
     message = (_("Your e-mail address is not your username. Try '%s' instead.") % user.username)
   return _display_login_form(request, message)
  elif (user.is_active and user.is_staff):
   login(request, user)
   user.last_login = datetime.datetime.now()
   user.save()
   return http.HttpResponseRedirect(request.path)
  else:
   return _display_login_form(request, ERROR_MESSAGE)
 return _checklogin

def staff_member_required ( view_func ) : def _checklogin ( request , * args , ** kwargs ) : if ( request . user . is_authenticated ( ) and request . user . is_staff ) : return view_func ( request , * args , ** kwargs ) 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'." if ( not request . POST . has_key ( LOGIN_FORM_KEY ) ) : if request . POST : message = _ ( 'Please log in again, because your session has expired.' ) else : message = '' return _display_login_form ( request , message ) if ( not request . session . test_cookie_worked ( ) ) : message = _ ( "Looks like your browser isn't configured to accept cookies. Please enable cookies, reload this page, and try again." ) return _display_login_form ( request , message ) username = request . POST . get ( 'username' , None ) password = request . POST . get ( 'password' , None ) user = authenticate ( username = username , password = password ) if ( user is None ) : message = ERROR_MESSAGE if ( '@' in username ) : try : user = User . objects . get ( email = username ) except User . DoesNotExist : message = _ ( "Usernames cannot contain the '@' character." ) else : message = ( _ ( "Your e-mail address is not your username. Try '%s' instead." ) % user . username ) return _display_login_form ( request , message ) elif ( user . is_active and user . is_staff ) : login ( request , user ) user . last_login = datetime . datetime . now ( ) user . save ( ) return http . HttpResponseRedirect ( request . path ) else : return _display_login_form ( request , ERROR_MESSAGE ) return _checklogin
decorator for views that checks that the user is logged in and is a staff member .