__init__.py 1023 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import json
  4. from collections import namedtuple
  5. from django.http import HttpResponse
  6. from apilib.systypes import StrEnum
  7. from apilib.utils_json import DescriptiveJSONEncoder
  8. class OfflineTaskType(StrEnum):
  9. AD_REPORT = u'广告报表'
  10. class MyJsonOkResponse(HttpResponse):
  11. def __init__(self, data, safe = True, ordered = False, **kwargs):
  12. if safe and not isinstance(data, dict):
  13. raise TypeError('In order to allow non-dict objects to be '
  14. 'serialized set the safe parameter to False')
  15. kwargs.setdefault('content_type', 'application/json')
  16. content = json.dumps(data, sort_keys = ordered, cls = DescriptiveJSONEncoder, ensure_ascii = False)
  17. super(MyJsonOkResponse, self).__init__(content = content, **kwargs)
  18. def json(self):
  19. return json.loads(self.content, encoding = 'utf-8')
  20. AdUser = namedtuple('AdUser', ['openId', 'feature_keys', 'feature_map'])