ResponseObject.py 7.3 KB

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