Topic.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. from alipay.aop.api.domain.TopicItem import TopicItem
  6. class Topic(object):
  7. def __init__(self):
  8. self._img_url = None
  9. self._link_url = None
  10. self._sub_title = None
  11. self._title = None
  12. self._topic_id = None
  13. self._topic_items = None
  14. @property
  15. def img_url(self):
  16. return self._img_url
  17. @img_url.setter
  18. def img_url(self, value):
  19. self._img_url = value
  20. @property
  21. def link_url(self):
  22. return self._link_url
  23. @link_url.setter
  24. def link_url(self, value):
  25. self._link_url = value
  26. @property
  27. def sub_title(self):
  28. return self._sub_title
  29. @sub_title.setter
  30. def sub_title(self, value):
  31. self._sub_title = value
  32. @property
  33. def title(self):
  34. return self._title
  35. @title.setter
  36. def title(self, value):
  37. self._title = value
  38. @property
  39. def topic_id(self):
  40. return self._topic_id
  41. @topic_id.setter
  42. def topic_id(self, value):
  43. self._topic_id = value
  44. @property
  45. def topic_items(self):
  46. return self._topic_items
  47. @topic_items.setter
  48. def topic_items(self, value):
  49. if isinstance(value, list):
  50. self._topic_items = list()
  51. for i in value:
  52. if isinstance(i, TopicItem):
  53. self._topic_items.append(i)
  54. else:
  55. self._topic_items.append(TopicItem.from_alipay_dict(i))
  56. def to_alipay_dict(self):
  57. params = dict()
  58. if self.img_url:
  59. if hasattr(self.img_url, 'to_alipay_dict'):
  60. params['img_url'] = self.img_url.to_alipay_dict()
  61. else:
  62. params['img_url'] = self.img_url
  63. if self.link_url:
  64. if hasattr(self.link_url, 'to_alipay_dict'):
  65. params['link_url'] = self.link_url.to_alipay_dict()
  66. else:
  67. params['link_url'] = self.link_url
  68. if self.sub_title:
  69. if hasattr(self.sub_title, 'to_alipay_dict'):
  70. params['sub_title'] = self.sub_title.to_alipay_dict()
  71. else:
  72. params['sub_title'] = self.sub_title
  73. if self.title:
  74. if hasattr(self.title, 'to_alipay_dict'):
  75. params['title'] = self.title.to_alipay_dict()
  76. else:
  77. params['title'] = self.title
  78. if self.topic_id:
  79. if hasattr(self.topic_id, 'to_alipay_dict'):
  80. params['topic_id'] = self.topic_id.to_alipay_dict()
  81. else:
  82. params['topic_id'] = self.topic_id
  83. if self.topic_items:
  84. if isinstance(self.topic_items, list):
  85. for i in range(0, len(self.topic_items)):
  86. element = self.topic_items[i]
  87. if hasattr(element, 'to_alipay_dict'):
  88. self.topic_items[i] = element.to_alipay_dict()
  89. if hasattr(self.topic_items, 'to_alipay_dict'):
  90. params['topic_items'] = self.topic_items.to_alipay_dict()
  91. else:
  92. params['topic_items'] = self.topic_items
  93. return params
  94. @staticmethod
  95. def from_alipay_dict(d):
  96. if not d:
  97. return None
  98. o = Topic()
  99. if 'img_url' in d:
  100. o.img_url = d['img_url']
  101. if 'link_url' in d:
  102. o.link_url = d['link_url']
  103. if 'sub_title' in d:
  104. o.sub_title = d['sub_title']
  105. if 'title' in d:
  106. o.title = d['title']
  107. if 'topic_id' in d:
  108. o.topic_id = d['topic_id']
  109. if 'topic_items' in d:
  110. o.topic_items = d['topic_items']
  111. return o