Example #1
0
def api_return(status, text='', json=False):
    content_type = 'text/html'
    if status == STATUS_OK and json:
        content_type = 'text/json'
    if text is None:
        if status == STATUS_ERROR:
            text = 'Error'
        elif status == STATUS_ERROR_NOT_FOUND:
            text = 'Resource Not Found'
        elif status == STATUS_ERROR_PERMISSIONS:
            text = 'Invalid username or password'
        elif status == STATUS_ERROR_BADMETHOD:
            text = 'Invalid request method'
        elif status == STATUS_OK:
            text = 'OK'

    r = HttpResponse(status=status, content=text, content_type=content_type)

    if status == STATUS_ERROR_BADMETHOD:
        r.Allow = 'POST'

    return r
Example #2
0
def api_return(status, text="", json=False):
    content_type = "text/plain"
    if status == STATUS_OK and json:
        content_type = "text/json"

    if text is None:
        if status == STATUS_ERROR:
            text = "Error"
        elif status == STATUS_ERROR_NOT_FOUND:
            text = "Resource Not Found"
        elif status == STATUS_ERROR_PERMISSIONS:
            text = "Invalid username or password"
        elif status == STATUS_ERROR_BADMETHOD:
            text = "Invalid request method"
        elif status == STATUS_OK:
            text = "OK"

    r = HttpResponse(status=status, content=text, content_type=content_type)

    if status == STATUS_ERROR_BADMETHOD:
        r.Allow = "POST"

    return r
Example #3
0
def api_return(status, text='', json=False):
    content_type = 'text/plain'
    if status == STATUS_OK and json:
        content_type = 'text/json'

    if text is None:
        if status == STATUS_ERROR:
            text = 'Error'
        elif status == STATUS_ERROR_NOT_FOUND:
            text = 'Resource Not Found'
        elif status == STATUS_ERROR_PERMISSIONS:
            text = 'Invalid username or password'
        elif status == STATUS_ERROR_BADMETHOD:
            text = 'Invalid request method'
        elif status == STATUS_OK:
            text = 'OK'

    r = HttpResponse(status=status, content=text, content_type=content_type)

    if status == STATUS_ERROR_BADMETHOD:
        r.Allow = 'POST'

    return r