staff_or_404 Decorator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
try:
    from functools import wraps
except ImportError:
    from django.utils.functional import wraps  # Python 2.4 fallback.

from django.http import Http404

def staff_or_404(view_func):
    """
    Decorator for views that checks that the user is logged in and is a staff
    member, raising a 404 if necessary.
    """
    def _checklogin(request, *args, **kwargs):
        if request.user.is_active and request.user.is_staff:
            # The user is valid. Continue to the admin page.
            return view_func(request, *args, **kwargs)

        else:   
            raise Http404

    return wraps(view_func)(_checklogin)

More like this

  1. Simple Age Verification Middleware by eculver 3 years, 9 months ago
  2. get_queryset_or_404 by mattpdx 5 years ago
  3. upload handler decorators by Rozza 4 years, 10 months ago
  4. LoginAsForm - Login as any User without a password by johnboxall 3 years, 11 months ago
  5. Send information mails to related staff members. by sleytr 5 years, 11 months ago

Comments

zhikai (on November 30, 2011):

Welcome to our http://www.cauggboot.com online store. A variety of the latest ugg boots are stocked on our website.They are: http://www.australiauggshoe.com

#

(Forgotten your password?)