forked from StarCharlie/SRTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
52 lines (46 loc) · 1.57 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from flask import jsonify
class Result:
@staticmethod
def error(code, message):
result = {"code": str(code), "message": str(message)}
return jsonify(result)
@staticmethod
def success(data):
result = {"code": "0", "message": "success"}
if isinstance(data, bytes):
result["data"] = str(data, 'utf-8')
else:
result["data"] = data
return jsonify(result)
@staticmethod
def success_infor(data, relation):
result = {"code": "0", "message": "success"}
if isinstance(data, bytes):
result["data"] = str(data, 'utf-8')
result["relation"] = str(relation, 'utf-8')
else:
result["data"] = data
result["relation"] = relation
return jsonify(result)
@staticmethod
def success_menu(data, menu):
result = {"code": "0", "message": "success"}
if isinstance(data, bytes):
result["data"] = str(data, 'utf-8')
result["menu"] = str(menu, 'utf-8')
else:
result["data"] = data
result["menu"] = menu
return jsonify(result)
@staticmethod
def success_search(data, total_number):
result = {"code": "0", "message": "success"}
if isinstance(data, bytes):
result["data"] = str(data, 'utf-8')
else:
result["data"] = data
if isinstance(data, bytes):
result["totalNumber"] = str(total_number, 'utf-8')
else:
result["totalNumber"] = total_number
return jsonify(result)