ArticleParagraph.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.ArticlePicture import ArticlePicture
  6. class ArticleParagraph(object):
  7. def __init__(self):
  8. self._pictures = None
  9. self._text = None
  10. @property
  11. def pictures(self):
  12. return self._pictures
  13. @pictures.setter
  14. def pictures(self, value):
  15. if isinstance(value, list):
  16. self._pictures = list()
  17. for i in value:
  18. if isinstance(i, ArticlePicture):
  19. self._pictures.append(i)
  20. else:
  21. self._pictures.append(ArticlePicture.from_alipay_dict(i))
  22. @property
  23. def text(self):
  24. return self._text
  25. @text.setter
  26. def text(self, value):
  27. self._text = value
  28. def to_alipay_dict(self):
  29. params = dict()
  30. if self.pictures:
  31. if isinstance(self.pictures, list):
  32. for i in range(0, len(self.pictures)):
  33. element = self.pictures[i]
  34. if hasattr(element, 'to_alipay_dict'):
  35. self.pictures[i] = element.to_alipay_dict()
  36. if hasattr(self.pictures, 'to_alipay_dict'):
  37. params['pictures'] = self.pictures.to_alipay_dict()
  38. else:
  39. params['pictures'] = self.pictures
  40. if self.text:
  41. if hasattr(self.text, 'to_alipay_dict'):
  42. params['text'] = self.text.to_alipay_dict()
  43. else:
  44. params['text'] = self.text
  45. return params
  46. @staticmethod
  47. def from_alipay_dict(d):
  48. if not d:
  49. return None
  50. o = ArticleParagraph()
  51. if 'pictures' in d:
  52. o.pictures = d['pictures']
  53. if 'text' in d:
  54. o.text = d['text']
  55. return o