OuterTargetingItem.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. class OuterTargetingItem(object):
  6. def __init__(self):
  7. self._type = None
  8. self._value_list = None
  9. @property
  10. def type(self):
  11. return self._type
  12. @type.setter
  13. def type(self, value):
  14. self._type = value
  15. @property
  16. def value_list(self):
  17. return self._value_list
  18. @value_list.setter
  19. def value_list(self, value):
  20. if isinstance(value, list):
  21. self._value_list = list()
  22. for i in value:
  23. self._value_list.append(i)
  24. def to_alipay_dict(self):
  25. params = dict()
  26. if self.type:
  27. if hasattr(self.type, 'to_alipay_dict'):
  28. params['type'] = self.type.to_alipay_dict()
  29. else:
  30. params['type'] = self.type
  31. if self.value_list:
  32. if isinstance(self.value_list, list):
  33. for i in range(0, len(self.value_list)):
  34. element = self.value_list[i]
  35. if hasattr(element, 'to_alipay_dict'):
  36. self.value_list[i] = element.to_alipay_dict()
  37. if hasattr(self.value_list, 'to_alipay_dict'):
  38. params['value_list'] = self.value_list.to_alipay_dict()
  39. else:
  40. params['value_list'] = self.value_list
  41. return params
  42. @staticmethod
  43. def from_alipay_dict(d):
  44. if not d:
  45. return None
  46. o = OuterTargetingItem()
  47. if 'type' in d:
  48. o.type = d['type']
  49. if 'value_list' in d:
  50. o.value_list = d['value_list']
  51. return o