from django.core.exceptions import PermissionDenied from functools import wraps from django.http import HttpResponseForbidden def level_required(level=0): def wrapper(view_func): def _decorator(request, *args, **kwargs): if (request.user.user_level.priority < level): return HttpResponseForbidden() response = view_func(request, *args, **kwargs) return response return wraps(view_func)(_decorator) return wrapper