123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- from django.shortcuts import HttpResponse
- import simplejson as json
- # 后面尽量尽量使用这个JSON响应类,模板未Controller/OauthManage.py
- class ResponseObject(object):
- def __init__(self, lang='en'):
- self.lang = lang
- def data(self, code, res={}):
- data_en = {
- 0: 'Success',
- 4: 'Operation failed',
- 5: 'Please try again one minute later!',
- 9: 'User accounts is not exist',
- 10: res,
- 13: 'Device is not exist !',
- 14: 'Device is not belong to you',
- 15: 'Not own service',
- 44: 'System error! Can not send email',
- 48: 'System object error!',
- 60: 'The app info has already exist',
- 89: 'Already send the code, please check it or get it again after 10m',
- 90: 'please check code or get it again after 5m',
- 100: 'Phone format error!',
- 101: 'Phone already existed!',
- 102: 'Phone doesn\'t exist!',
- 103: 'Mail already existed!',
- 104: 'Account doesn\'t exist!',
- 105: 'Email format error!',
- 106: 'Create User Error',
- 107: 'The username not conform to the rules!',
- 108: 'Email format error!',
- 109: 'The password not conform to the rules!',
- 110: 'user is not activated',
- 111: 'Error password',
- 112: 'update password error!',
- 113: 'This userID does not exist!',
- 114: 'Delete user failure error',
- 115: 'The userID of the user to delete does not exist!',
- 118: 'You do not enter the password two times!',
- 120: 'The code has expired',
- 121: 'The verification code is wrong!',
- 150: 'Wrong superID is None or userID',
- 160: 'The All Equipment has been shared by the User!',
- 171: 'Delete Equipment sharing failed',
- 172: 'There is no Equipment for this User!',
- 173: 'The UID does not exist!',
- 174: 'The user equipment has already existed!',
- 175: 'The user equipment has already binding!',
- 176: 'Delete equipment error',
- 177: 'Update equipment error',
- 178: 'ADD equipment error',
- 179: 'Device nickname cannot be repeated',
- 180: 'UID specification error',
- 190: 'The rid does not exist!',
- 191: 'The roleName does not exist!',
- 192: 'Delete role error',
- 193: 'role can not be deleted!',
- 194: 'Update role error',
- 195: 'role can not be updated!',
- 306: 'The link has expired!',
- 309: 'Please ReLogin! errmsg token',
- 403: 'API ERROR!',
- 404: 'You don not have permission to access this!',
- 414: 'Client error ! Please confirm the request path!',
- 424: 'Database Error !',
- 444: 'Wrong parameters!',
- 500: 'Query Database Error:',
- 501: 'Update database error!',
- 502: 'The fields do not exist!',
- 601: 'Delete permission denied!',
- 602: 'Modify permission denied!',
- 605: 'Upload permission denied!',
- 606: 'User has not assigned role!',
- 611: 'Add permission denied!',
- 612: 'Query permission denied!',
- 615: 'SuperAdmin does not exist!',
- 616: 'User does not exist!',
- 800: 'Request KEY is None!',
- 801: 'Wrong request KEY!',
- 802: 'Parameter error!',
- 803: 'Wrong parameter',
- 804: 'Share Error! content or sharedAll must be provided!',
- 805: 'Un share Error! content or unsharedAll must be provided!',
- 806: 'The content parameter is incomplete!',
- 807: 'The role has already existed!',
- 808: 'Add a new role to the wrong',
- 816: 'Add a new permissions error',
- 817: 'The permissions do not exist!',
- 818: 'Delete permission failed',
- 700: 'Upload file error',
- 701: 'The file does not exist!',
- 900: 'There is no information about this version!',
- 901: 'Getting URL failure!',
- 902: 'No update!',
- 903: 'Error filename',
- 906: 'Cause of file operation error',
- 907: 'The download file does not exist!',
- 910: 'Much downloads. Please wait a moment...',
- }
- data_cn = {
- 0: '成功',
- 4: '操作失败',
- 5: '请一分钟后再尝试',
- 9: '用户账号不存在',
- 10: res,
- 13: '设备不存在',
- 14: '设备不属于您',
- 15: '您尚未打开此服务',
- 44: '系统错误!无法发送电子邮件',
- 48: '系统对象错误',
- 60: 'APP信息已经存在',
- 89: '已发验证码,请检测或10分钟后重新获取。',
- 90: '请检测或5分钟后重新获取。',
- 100: '手机格式错误!',
- 101: '手机已存在!',
- 102: '手机不存在!',
- 103: '邮箱已存在!',
- 104: '账户不存在!',
- 105: '邮箱格式错误!',
- 106: '创建用户错误',
- 107: '用户名格式不符合!',
- 108: '邮箱格式错误!',
- 109: '密码格式不符合!',
- 110: '用户未激活!',
- 111: '您输入的密码不正确!',
- 112: '未知错误不能更新密码!',
- 113: '此用户标识不存在!',
- 114: '删除用户失败错误',
- 115: '删除用户的用户名不存在!',
- 118: '你不输入密码两次!',
- 120: '验证码过期',
- 121: '验证码错了!',
- 150: '超级用户或用户id错误',
- 160: '所有设备已被用户共享!',
- 171: '删除设备共享失败',
- 172: '这个用户没有设备!',
- 173: '设备UID不存在!',
- 174: '用户设备已经存在!',
- 175: '用户设备已经绑定了!',
- 176: '删除设备错误',
- 177: '更新设备错误',
- 178: '添加设备错误',
- 179: '设备名称不能重复',
- 180: 'UID规格错误',
- 190: '角色rid不存在!',
- 191: '角色名不存在!',
- 192: '删除角色错误',
- 193: '未知的错误导致角色不能被删除!',
- 194: '更新角色错误',
- 195: '未知的错误导致角色无法更新!',
- 306: '链接已超过有效期!',
- 309: '请重新登录!',
- 403: 'API错误!',
- 404: '您没有访问的权限!',
- 414: '客户端错误!请确认请求路径!',
- 424: '数据库错误!',
- 444: '请确认参数的正确性!',
- 500: '查询数据库错误!',
- 501: '更新数据库错误!',
- 502: '在数据库中,参数字段不存在!',
- 601: '没有权限删除!',
- 602: '没有权限修改!',
- 605: '没有权限上传!',
- 606: '用户没有分配角色!',
- 611: '没有权限添加!',
- 612: '没有权限查询!',
- 615: '超级管理员帐户不存在!',
- 616: '用户帐户不存在!',
- 800: '请求参数不存在!',
- 801: '错误的请求参数!',
- 802: 'content参数错误!',
- 803: 'content参数格式错误',
- 804: 'content或sharedAll参数没有传递',
- 805: 'content或unsharedAll参数没有传递',
- 806: 'content参数不完整!',
- 807: '角色已经存在!',
- 808: '添加新角色错误',
- 816: '新增权限错误',
- 817: '权限不存在',
- 818: '删除权限错误',
- 700: '上传文件错误',
- 701: '文件不存在',
- 900: '版本信息不存在',
- 901: '获取链接失败',
- 902: '无更新!',
- 903: '文件名不符合!',
- 906: '文件操作错误',
- 907: '文件不存在!',
- 910: '下载太多,请稍等…',
- }
- if self.lang == 'cn':
- msg = data_cn
- else:
- msg = data_en
- try:
- message = msg[code]
- except Exception as e:
- message = '系统错误,code不存在'
- return {'result_code': code, 'reason': message, 'result': res, 'error_code': code}
- def formal(self, code, res={}):
- formal_data = self.data(code, res)
- return json.dumps(formal_data, ensure_ascii=False)
- def json(self, code, res={}):
- result = self.formal(code, res)
- return HttpResponse(result)
|