def permission_required(*actions, obj=None, raise_exception=False):
def checker(user):<EOL><INDENT>ok = False<EOL>if user.is_authenticated() and check_perms(user, actions, [obj]):<EOL><INDENT>ok = True<EOL><DEDENT>if raise_exception and not ok:<EOL><INDENT>raise PermissionDenied<EOL><DEDENT>else:<EOL><INDENT>return ok<EOL><DEDENT><DEDENT>def decorator(view_func):<EOL><INDENT>@wraps(view_func, assigned=available_attrs(view_func))<EOL>def _wrapped_view(request, *args, **kwargs):<EOL><INDENT>if checker(request.user):<EOL><INDENT>return view_func(request, *args, **kwargs)<EOL><DEDENT><DEDENT>return _wrapped_view<EOL><DEDENT>return decorator<EOL>
Permission checking decorator -- works like the
    ``permission_required`` decorator in the default Django
    authentication system, except that it takes a sequence of actions
    to check, an object must be supplied, and the user must have
    permission to perform all of the actions on the given object for
    the permissions test to pass.  *Not actually sure how useful this
    is going to be: in any case where obj is not None, it's going to
    be tricky to get the object into the decorator.  Class-based views
    are definitely best here...*