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...*

def permission_required(*actions, obj=None, raise_exception=False):
    """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...*

    """
    def checker(user):
        ok = False
        if user.is_authenticated() and check_perms(user, actions, [obj]):
            ok = True
        if raise_exception and not ok:
            raise PermissionDenied
        else:
            return ok

    def decorator(view_func):
        @wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            if checker(request.user):
                return view_func(request, *args, **kwargs)
        return _wrapped_view
    return decorator