(slug, http_status_code=None,
                                     get_response=None, **assignment)
return decorate
A version of the requires privilege decorator which returns an
    HttpResponse object with an HTTP Status Code of 401 by default
    and content_type application/json if the privilege is not found.

    `get_response` is an optional parameter where you can specify the
    format of response given an error message and status code.
    The default response is:
    ```
    {
        'code': http_status_Code,
        'message': error_message
    }
    ```
A version of the requires privilege decorator which returns an
    HttpResponse object with an HTTP Status Code of 401 by default
    and content_type application/json if the privilege is not found.
A version of the requires privilege decorator which returns an HttpResponse object with an HTTP Status Code of 401 by default and content_type application / json if the privilege is not found .
def requires_privilege_json_response(slug, http_status_code=None,
                                     get_response=None, **assignment):
    """
    A version of the requires privilege decorator which returns an
    HttpResponse object with an HTTP Status Code of 401 by default
    and content_type application/json if the privilege is not found.

    `get_response` is an optional parameter where you can specify the
    format of response given an error message and status code.
    The default response is:
    ```
    {
        'code': http_status_Code,
        'message': error_message
    }
    ```
    """
    http_status_code = http_status_code or 401
    if get_response is None:
        get_response = lambda msg, code: {'code': code, 'message': msg}

    def decorate(fn):
        @wraps(fn)
        def wrapped(request, *args, **kwargs):
            try:
                return requires_privilege(slug, **assignment)(fn)(
                    request, *args, **kwargs)
            except PermissionDenied:
                error_message = "You have lost access to this feature."
                response = get_response(error_message, http_status_code)
                return HttpResponse(json.dumps(response),
                                    content_type="application/json", status=401)
        return wrapped
    return decorate
def requires_privilege_json_response ( slug , http_status_code = None , get_response = None , * * assignment ) : http_status_code = http_status_code or 401 if get_response is None : get_response = lambda msg , code : { 'code' : code , 'message' : msg } def decorate ( fn ) : @ wraps ( fn ) def wrapped ( request , * args , * * kwargs ) : try : return requires_privilege ( slug , * * assignment ) ( fn ) ( request , * args , * * kwargs ) except PermissionDenied : error_message = "You have lost access to this feature." response = get_response ( error_message , http_status_code ) return HttpResponse ( json . dumps ( response ) , content_type = "application/json" , status = 401 ) return wrapped return decorate