def METHOD_NAME(codename):
    """
    Wraps view function, testing whether the current user has the
    specified permission.
    """
    def wrapper_function(view_fn):
        @wraps(view_fn)
        def wrapped(request, instance, *args, **kwargs):
            from treemap.audit import Role
            role = Role.objects.get_role(instance, request.user)
            if role.has_permission(codename):
                return view_fn(request, instance, *args, **kwargs)
            else:
                raise PermissionDenied
        return wrapped
    return wrapper_function