validation.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import datetime
  4. from apps.web.constant import AdType
  5. from apps.web.core.validation import Schema, Required, Coerce, In, Boolean, Any, Url, REMOVE_EXTRA
  6. getAdPreAllocatedDevice_query_schema = Schema(
  7. {
  8. Required("devCondition"): Schema([{"agentIdList": list,"dealerIdList":list,"groupIdList":list}]),
  9. Required("addressTypeList"): list,
  10. Required("devTypeList"): list
  11. })
  12. advertisementSchema = Schema(
  13. {
  14. #: 广告基本属性
  15. #:: 编辑时需要广告ID
  16. 'id': basestring,
  17. Required('name') : basestring,
  18. 'adType': In(AdType.choices()),
  19. 'online': Boolean(),
  20. 'img': basestring,
  21. 'word': basestring,
  22. 'link': Any(Url(), None, ""),
  23. 'startTime': lambda _: datetime.datetime.strptime(_, "%Y-%m-%d %H:%M:%S"),
  24. 'endTime': lambda _: datetime.datetime.strptime(_, "%Y-%m-%d %H:%M:%S"),
  25. 'script': Any(basestring, None),
  26. 'scriptType': Any(basestring, None),
  27. #: 过滤器
  28. 'devCondition': list,
  29. 'devTypeList': list,
  30. 'addressTypeList': list,
  31. #: 接受广告投递的设备
  32. 'devList': list,
  33. #:: 面向用户的广告过滤器
  34. 'targetSex': In([u'男', u'女', '*']),
  35. 'targetPhoneOS': In([[], [u'iOS'], [u'Android'],[u'iOS', u'Android']]),
  36. 'gateway': In([[], [u'wechat'], [u'alipay'], [u'wechat', u'alipay']]),
  37. #: 定价
  38. 'price': Coerce(float),
  39. 'agentPrice': Coerce(float),
  40. 'dealerPrice': Coerce(float),
  41. #: 配置项
  42. 'configs': dict,
  43. 'fansType': In(['person', 'official']),
  44. 'offlineFansNumber': int,
  45. 'PIN': basestring,
  46. }, extra=REMOVE_EXTRA)