ButtonObject.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.SubButton import SubButton
  6. class ButtonObject(object):
  7. def __init__(self):
  8. self._action_param = None
  9. self._action_type = None
  10. self._icon = None
  11. self._name = None
  12. self._sub_button = None
  13. @property
  14. def action_param(self):
  15. return self._action_param
  16. @action_param.setter
  17. def action_param(self, value):
  18. self._action_param = value
  19. @property
  20. def action_type(self):
  21. return self._action_type
  22. @action_type.setter
  23. def action_type(self, value):
  24. self._action_type = value
  25. @property
  26. def icon(self):
  27. return self._icon
  28. @icon.setter
  29. def icon(self, value):
  30. self._icon = value
  31. @property
  32. def name(self):
  33. return self._name
  34. @name.setter
  35. def name(self, value):
  36. self._name = value
  37. @property
  38. def sub_button(self):
  39. return self._sub_button
  40. @sub_button.setter
  41. def sub_button(self, value):
  42. if isinstance(value, list):
  43. self._sub_button = list()
  44. for i in value:
  45. if isinstance(i, SubButton):
  46. self._sub_button.append(i)
  47. else:
  48. self._sub_button.append(SubButton.from_alipay_dict(i))
  49. def to_alipay_dict(self):
  50. params = dict()
  51. if self.action_param:
  52. if hasattr(self.action_param, 'to_alipay_dict'):
  53. params['action_param'] = self.action_param.to_alipay_dict()
  54. else:
  55. params['action_param'] = self.action_param
  56. if self.action_type:
  57. if hasattr(self.action_type, 'to_alipay_dict'):
  58. params['action_type'] = self.action_type.to_alipay_dict()
  59. else:
  60. params['action_type'] = self.action_type
  61. if self.icon:
  62. if hasattr(self.icon, 'to_alipay_dict'):
  63. params['icon'] = self.icon.to_alipay_dict()
  64. else:
  65. params['icon'] = self.icon
  66. if self.name:
  67. if hasattr(self.name, 'to_alipay_dict'):
  68. params['name'] = self.name.to_alipay_dict()
  69. else:
  70. params['name'] = self.name
  71. if self.sub_button:
  72. if isinstance(self.sub_button, list):
  73. for i in range(0, len(self.sub_button)):
  74. element = self.sub_button[i]
  75. if hasattr(element, 'to_alipay_dict'):
  76. self.sub_button[i] = element.to_alipay_dict()
  77. if hasattr(self.sub_button, 'to_alipay_dict'):
  78. params['sub_button'] = self.sub_button.to_alipay_dict()
  79. else:
  80. params['sub_button'] = self.sub_button
  81. return params
  82. @staticmethod
  83. def from_alipay_dict(d):
  84. if not d:
  85. return None
  86. o = ButtonObject()
  87. if 'action_param' in d:
  88. o.action_param = d['action_param']
  89. if 'action_type' in d:
  90. o.action_type = d['action_type']
  91. if 'icon' in d:
  92. o.icon = d['icon']
  93. if 'name' in d:
  94. o.name = d['name']
  95. if 'sub_button' in d:
  96. o.sub_button = d['sub_button']
  97. return o