ResponseObject.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. # 后面尽量尽量使用这个JSON响应类,模板未Controller/OauthManage.py
  4. class ResponseObject(object):
  5. def __init__(self, lang='en'):
  6. self.lang = lang
  7. def data(self, code, res={}):
  8. data_en = {
  9. 0: 'Success',
  10. 4: 'Operation failed',
  11. 5: 'Please try again one minute later!',
  12. 9: 'User accounts is not exist',
  13. 10: res,
  14. 13: 'Device is not exist !',
  15. 14: 'Device is not belong to you',
  16. 15: 'Not own service',
  17. 44: 'System error! Can not send email',
  18. 48: 'System object error!',
  19. 60: 'The app info has already exist',
  20. 89: 'Already send the code, please check it or get it again after 10m',
  21. 90: 'please check code or get it again after 5m',
  22. 100: 'Phone format error!',
  23. 101: 'Phone already existed!',
  24. 102: 'Phone doesn\'t exist!',
  25. 103: 'Mail already existed!',
  26. 104: 'Account doesn\'t exist!',
  27. 105: 'Email format error!',
  28. 106: 'Create User Error',
  29. 107: 'The username not conform to the rules!',
  30. 108: 'Email format error!',
  31. 109: 'The password not conform to the rules!',
  32. 110: 'user is not activated',
  33. 111: 'Error password',
  34. 112: 'update password error!',
  35. 113: 'This userID does not exist!',
  36. 114: 'Delete user failure error',
  37. 115: 'The userID of the user to delete does not exist!',
  38. 118: 'You do not enter the password two times!',
  39. 120: 'The code has expired',
  40. 121: 'The verification code is wrong!',
  41. 150: 'Wrong superID is None or userID',
  42. 160: 'The All Equipment has been shared by the User!',
  43. 171: 'Delete Equipment sharing failed',
  44. 172: 'There is no Equipment for this User!',
  45. 173: 'The UID does not exist!',
  46. 174: 'The user equipment has already existed!',
  47. 175: 'The user equipment has already binding!',
  48. 176: 'Delete equipment error',
  49. 177: 'Update equipment error',
  50. 178: 'ADD equipment error',
  51. 179: 'Device nickname cannot be repeated',
  52. 180: 'UID specification error',
  53. 190: 'The rid does not exist!',
  54. 191: 'The roleName does not exist!',
  55. 192: 'Delete role error',
  56. 193: 'role can not be deleted!',
  57. 194: 'Update role error',
  58. 195: 'role can not be updated!',
  59. 306: 'The link has expired!',
  60. 309: 'Please ReLogin! errmsg token',
  61. 403: 'API ERROR!',
  62. 404: 'You don not have permission to access this!',
  63. 414: 'Client error ! Please confirm the request path!',
  64. 424: 'Database Error !',
  65. 444: 'Wrong parameters!',
  66. 500: 'Query Database Error:',
  67. 501: 'Update database error!',
  68. 502: 'The fields do not exist!',
  69. 601: 'Delete permission denied!',
  70. 602: 'Modify permission denied!',
  71. 605: 'Upload permission denied!',
  72. 606: 'User has not assigned role!',
  73. 611: 'Add permission denied!',
  74. 612: 'Query permission denied!',
  75. 615: 'SuperAdmin does not exist!',
  76. 616: 'User does not exist!',
  77. 800: 'Request KEY is None!',
  78. 801: 'Wrong request KEY!',
  79. 802: 'Parameter error!',
  80. 803: 'Wrong parameter',
  81. 804: 'Share Error! content or sharedAll must be provided!',
  82. 805: 'Un share Error! content or unsharedAll must be provided!',
  83. 806: 'The content parameter is incomplete!',
  84. 807: 'The role has already existed!',
  85. 808: 'Add a new role to the wrong',
  86. 816: 'Add a new permissions error',
  87. 817: 'The permissions do not exist!',
  88. 818: 'Delete permission failed',
  89. 700: 'Upload file error',
  90. 701: 'The file does not exist!',
  91. 900: 'There is no information about this version!',
  92. 901: 'Getting URL failure!',
  93. 902: 'No update!',
  94. 903: 'Error filename',
  95. 906: 'Cause of file operation error',
  96. 907: 'The download file does not exist!',
  97. 910: 'Much downloads. Please wait a moment...',
  98. }
  99. data_cn = {
  100. 0: '成功',
  101. 4: '操作失败',
  102. 5: '请一分钟后再尝试',
  103. 9: '用户账号不存在',
  104. 10: res,
  105. 13: '设备不存在',
  106. 14: '设备不属于您',
  107. 15: '您尚未打开此服务',
  108. 44: '系统错误!无法发送电子邮件',
  109. 48: '系统对象错误',
  110. 60: 'APP信息已经存在',
  111. 89: '已发验证码,请检测或10分钟后重新获取。',
  112. 90: '请检测或5分钟后重新获取。',
  113. 100: '手机格式错误!',
  114. 101: '手机已存在!',
  115. 102: '手机不存在!',
  116. 103: '邮箱已存在!',
  117. 104: '账户不存在!',
  118. 105: '邮箱格式错误!',
  119. 106: '创建用户错误',
  120. 107: '用户名格式不符合!',
  121. 108: '邮箱格式错误!',
  122. 109: '密码格式不符合!',
  123. 110: '用户未激活!',
  124. 111: '您输入的密码不正确!',
  125. 112: '未知错误不能更新密码!',
  126. 113: '此用户标识不存在!',
  127. 114: '删除用户失败错误',
  128. 115: '删除用户的用户名不存在!',
  129. 118: '你不输入密码两次!',
  130. 120: '验证码过期',
  131. 121: '验证码错了!',
  132. 150: '超级用户或用户id错误',
  133. 160: '所有设备已被用户共享!',
  134. 171: '删除设备共享失败',
  135. 172: '这个用户没有设备!',
  136. 173: '设备UID不存在!',
  137. 174: '用户设备已经存在!',
  138. 175: '用户设备已经绑定了!',
  139. 176: '删除设备错误',
  140. 177: '更新设备错误',
  141. 178: '添加设备错误',
  142. 179: '设备名称不能重复',
  143. 180: 'UID规格错误',
  144. 190: '角色rid不存在!',
  145. 191: '角色名不存在!',
  146. 192: '删除角色错误',
  147. 193: '未知的错误导致角色不能被删除!',
  148. 194: '更新角色错误',
  149. 195: '未知的错误导致角色无法更新!',
  150. 306: '链接已超过有效期!',
  151. 309: '请重新登录!',
  152. 403: 'API错误!',
  153. 404: '您没有访问的权限!',
  154. 414: '客户端错误!请确认请求路径!',
  155. 424: '数据库错误!',
  156. 444: '请确认参数的正确性!',
  157. 500: '查询数据库错误!',
  158. 501: '更新数据库错误!',
  159. 502: '在数据库中,参数字段不存在!',
  160. 601: '没有权限删除!',
  161. 602: '没有权限修改!',
  162. 605: '没有权限上传!',
  163. 606: '用户没有分配角色!',
  164. 611: '没有权限添加!',
  165. 612: '没有权限查询!',
  166. 615: '超级管理员帐户不存在!',
  167. 616: '用户帐户不存在!',
  168. 800: '请求参数不存在!',
  169. 801: '错误的请求参数!',
  170. 802: 'content参数错误!',
  171. 803: 'content参数格式错误',
  172. 804: 'content或sharedAll参数没有传递',
  173. 805: 'content或unsharedAll参数没有传递',
  174. 806: 'content参数不完整!',
  175. 807: '角色已经存在!',
  176. 808: '添加新角色错误',
  177. 816: '新增权限错误',
  178. 817: '权限不存在',
  179. 818: '删除权限错误',
  180. 700: '上传文件错误',
  181. 701: '文件不存在',
  182. 900: '版本信息不存在',
  183. 901: '获取链接失败',
  184. 902: '无更新!',
  185. 903: '文件名不符合!',
  186. 906: '文件操作错误',
  187. 907: '文件不存在!',
  188. 910: '下载太多,请稍等…',
  189. }
  190. if self.lang == 'cn':
  191. msg = data_cn
  192. else:
  193. msg = data_en
  194. try:
  195. message = msg[code]
  196. except Exception as e:
  197. message = '系统错误,code不存在'
  198. return {'result_code': code, 'reason': message, 'result': res, 'error_code': code}
  199. def formal(self, code, res={}):
  200. formal_data = self.data(code, res)
  201. return json.dumps(formal_data, ensure_ascii=False)
  202. def json(self, code, res={}):
  203. result = self.formal(code, res)
  204. return HttpResponse(result)