ResponseObject.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. class ResponseObject(object):
  4. def __init__(self, lang='cn'):
  5. self.lang = lang
  6. def data(self, code, res={}):
  7. data_cn = {
  8. 0: '成功',
  9. 5: '请一分钟后再尝试',
  10. 8: '用户账号已存在',
  11. 9: '用户账号不存在',
  12. 10: res,
  13. 42: '两次输入的新密码错误',
  14. 43: '客户端服务器已关闭,请下载新版本使用',
  15. 44: '系统错误,发送邮件失败',
  16. 45: '系统错误,生成令牌出错!',
  17. 46: '系统错误,发送短信失败!',
  18. 47: '旧密码不正确',
  19. 74: '关联旧用户失败!',
  20. 79: '您已经申请过重置密码,请到邮箱进行确认!',
  21. 89: '您已经获得了验证码,请在10分钟后检查或再次确认。',
  22. 99: '账户或密码错误',
  23. 101: '手机的用户账号已经存在!',
  24. 102: '手机的用户账号不存在!',
  25. 103: '邮箱用户帐户已经存在!',
  26. 104: '邮箱用户帐户不存在!',
  27. 107: '用户名格式不符合规则!',
  28. 108: '邮箱格式不符合规则!',
  29. 110: '因为用户未激活,用户是无效用户!',
  30. 111: '您输入的密码不正确!',
  31. 120: '验证码已过期或不存在、请重新获得验证码!',
  32. 121: '验证码错了!',
  33. 138: '手机格式不符合规则!',
  34. 173: '数据不存在!',
  35. 174: '数据已存在',
  36. 305: '令牌格式是错误的,相关参数是不存在的!',
  37. 307: '令牌已过期!',
  38. 309: '你没有权限访问',
  39. 404: 'You don not have permission to access this!',
  40. 444: '请确认参数的正确性!',
  41. 1112: '您输入的两次密码不一致!',
  42. 208: '只能预定当天的或者以后的!',
  43. }
  44. data_en = {
  45. 0: 'Success',
  46. 5: 'Please try again one minute later!',
  47. 8: 'User accounts already exist',
  48. 9: 'User accounts is not exist',
  49. 10: res,
  50. 42: 'The new password entered twice is incorrect',
  51. 43: 'The client server is closed. Please download the new version for use',
  52. 44: 'System error,send email fail!',
  53. 45: 'System error,generate token fail!',
  54. 46: 'System error, sending SMS failed!',
  55. 47: 'Old password is incorrect',
  56. 74: 'Failed to connect old users!',
  57. 79: 'You have applied for reset password, please go to email for confirmation!',
  58. 89: 'You have already obtained the verification code, please check it or get it again after 10 minutes.',
  59. 99: ' ERROR Incorrect account or password',
  60. 101: 'The user account of the mobile phone has already existed!',
  61. 102: 'The user account of the mobile phone does not exist!',
  62. 103: 'The mailbox user account has already existed!',
  63. 104: 'The mailbox user account does not exist!',
  64. 107: 'The username format does not conform to the rules!',
  65. 108: 'The mailbox format does not conform to the rules! ',
  66. 110: 'Because the user is not activated, the user is an invalid user!',
  67. 111: 'The password you entered is incorrect!',
  68. 120: 'The captcha has expired or does not exist, please obtain the captcha again!',
  69. 121: 'The verification code is wrong!',
  70. 138: 'The phone format does not conform to the rules! ',
  71. 173: 'Data does not exists!',
  72. 174: 'Data already exists',
  73. 305: 'The Token format is wrong and the related parameter is None!',
  74. 307: 'The Token has expired!',
  75. 309: 'You have no access',
  76. 404: 'You don not have permission to access this!',
  77. 444: 'Please confirm the correctness of the parameters!',
  78. 1112: 'The two passwords you entered do not match!',
  79. }
  80. if self.lang == 'cn':
  81. msg = data_cn
  82. else:
  83. msg = data_en
  84. try:
  85. message = msg[code]
  86. except Exception as e:
  87. message = '系统错误,code不存在'
  88. return {'code': code, 'msg': message, 'res': res}
  89. def formal(self, code, res={}):
  90. formal_data = self.data(code, res)
  91. return json.dumps(formal_data,ensure_ascii=False)
  92. def json(self, code, res={}):
  93. result = self.formal(code, res)
  94. return HttpResponse(result)