from django.shortcuts import HttpResponse
import simplejson as json


class ResponseObject(object):

    def __init__(self, lang='cn'):
        self.lang = lang

    def json(self, code, res={}, extra={}):
        msg_data = {
            0: 'Success',
            10: res,
            233: '您已抽过奖',
            300: '请输入正确的手机号码',
            301: '验证码已发过，请等待',
            309: 'Please ReLogin! errmsg token',
            401: 'Invalid credentials !',
            403: 'permission denied',
            404: 'Server error',
            407: '验证码过期',
            409: '验证码错误',
            414: 'Invalid request path !',
            444: 'Wrong Parameter!',
            473: 'The same value exists !'
        }
        result = {'code': code, 'msg': msg_data[code], 'res': res}
        if extra:
            for k in extra:
                result[k] = extra[k]
        return HttpResponse(json.dumps(result, ensure_ascii=False))
