ResponseObject.py 8.5 KB

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