Esempio n. 1
0
def json_detail_render_sse(code, data=None, message=None):
    if data is None:
        data = []
    if message is None:
        message = MSG_MAP.get(code)
    resp = dict(code=code, message=message, data=data)
    return json.dumps(resp)
Esempio n. 2
0
    def __init__(self, message=None):
        if message:
            self.message = message
        else:
            self.message = MSG_MAP.get(self.code)

        super(Error, self).__init__(self.message)
Esempio n. 3
0
def format_response(res):
    if 'code' not in res.keys():
        res['code'] = 0
    if 'message' not in res.keys():
        res['message'] = MSG_MAP.get(res['code'], '')
    if 'data' not in res.keys():
        res['data'] = []
    return res
Esempio n. 4
0
def json_detail_render(code, data=None, message=None, total=None):
    if data is None:
        data = []
    if message is None:
        message = MSG_MAP.get(code)
    resp = dict(code=code, message=message, data=data)
    if total:
        resp['total'] = total
    return _render(resp)
Esempio n. 5
0
def json_list_render(code, data, limit, offset, message=None):
    if message is None:
        message = MSG_MAP.get(code)
    resp = dict(code=code,
                limit=limit,
                offset=offset,
                message=message,
                data=data)
    return _render(resp)
Esempio n. 6
0
def json_list_render2(code, data, page_size, page_index, total, message=None):
    if message is None:
        message = MSG_MAP.get(code)
    resp = dict(code=code,
                page_size=page_size,
                page_index=page_index,
                total=total,
                message=message,
                data=data)
    return _render(resp)
Esempio n. 7
0
def json_token_render(code, token, message=None):
    if message is None:
        message = MSG_MAP.get(code)
    resp = dict(code=code, token=token, message=message)
    return _render(resp)
Esempio n. 8
0
def json_render(response):
    if 'code' not in response.keys():
        response['code'] = 0
    if 'message' not in response.keys():
        response['message'] = MSG_MAP.get(response['code'], '')
    return _render(response)