import urlparse
from functools import wraps

from django.contrib import messages
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.utils.translation import ugettext_lazy as _


def staff_member_required(view_func, login_url=None):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member. The user is redirected to the login page specified by *login_url*
    if not authenticated.

    This decorator is based on the admin decorator provided by the the django
    ``auth`` and ``admin`` packages.
    """
    if login_url is None:
        login_url = reverse_lazy('customer:login')

    @wraps(view_func)
    def _checklogin(request, *args, **kwargs):
        if request.user.is_active and request.user.is_staff:
            return view_func(request, *args, **kwargs)

        # If the login url is the same scheme and net location then just
        # use the path as the "next" url.
        path = request.build_absolute_uri()

        login_scheme, login_netloc = urlparse.urlparse(login_url)[:2]
        current_scheme, current_netloc = urlparse.urlparse(path)[:2]
        if ((not login_scheme or login_scheme == current_scheme) and
            (not login_netloc or login_netloc == current_netloc)):
            path = request.get_full_path()

        messages.warning(request, _("You must log in to access this page"))

        from django.contrib.auth.views import redirect_to_login
        return redirect_to_login(path, login_url, REDIRECT_FIELD_NAME)

    return _checklogin

@@ -92,95 +92,203 @@
 o.co
-re.urlresolvers import reverse_lazy%0Afrom django.contrib.auth import REDIRECT_FIELD_NAME
+ntrib.auth import REDIRECT_FIELD_NAME%0Afrom django.contrib.auth.views import redirect_to_login%0Afrom django.core.exceptions import PermissionDenied%0Afrom django.core.urlresolvers import reverse_lazy
 %0Afro
@@ -412,39 +412,14 @@
     
-Decorator for views that checks
+Ensure
  tha
@@ -436,44 +436,33 @@
  is 
+a 
 logged
- 
+-
 in 
-and is a 
 staff
-%0A   
  member.
  The
@@ -461,20 +461,37 @@
 ber.
- The user is
+%0A%0A    * If not authenticated,
  red
@@ -499,28 +499,13 @@
 rect
-ed
  to 
-the login page
+a
  spe
@@ -515,48 +515,54 @@
 ied 
-by *
 login
-_url*
+ URL.
 %0A    
-i
+* I
 f not 
-authenticated.
+staff, show a 403 page
 %0A%0A  
@@ -598,14 +598,8 @@
 the 
-admin 
 deco
@@ -608,70 +608,143 @@
 tor 
-provided by the the django%0A    %60%60auth%60%60 and %60%60admin%60%60 packages
+with the same name from%0A    django.contrib.admin.view.decorators.  This one is superior as it allows a%0A    redirect URL to be specified
 .%0A  
@@ -1013,16 +1013,127 @@
 wargs)%0A%0A
+        # If user is not logged in, redirect to login page%0A        if not request.user.is_authenticated():%0A    
         
@@ -1205,16 +1205,20 @@
         
+    
 # use th
@@ -1243,32 +1243,36 @@
 t%22 url.%0A        
+ 
+   
 path = request.b
@@ -1291,25 +1291,26 @@
 e_uri()%0A
-%0A
+  
         
 login_sc
@@ -1297,24 +1297,26 @@
 )%0A          
+  
 login_scheme
@@ -1373,16 +1373,20 @@
         
+    
 current_
@@ -1446,16 +1446,20 @@
         
+ 
+   
 if ((not
@@ -1523,16 +1523,20 @@
         
+   
+ 
 (not log
@@ -1586,32 +1586,36 @@
 )):%0A            
+    
 path = request.g
@@ -1638,16 +1638,20 @@
         
+ 
+   
 messages
@@ -1714,73 +1714,12 @@
 %22))%0A
-%0A
     
-    from django.contrib.auth.views import redirect_to_login%0A
     
@@ -1784,16 +1784,127 @@
 LD_NAME)
+%0A        else:%0A            # User does not have permission to view this page%0A            raise PermissionDenied
 %0A%0A    re

Extend staff_member_required to raise 403 on non-staff users