action.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding:utf-8 -*-
  2. # Copyright 2017 Xiaomi, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. __author__ = 'Ulric Qin'
  16. from .bean import Bean
  17. class Action(Bean):
  18. _tbl = 'action'
  19. _cols = 'id, uic, url, callback, ' \
  20. 'before_callback_sms, before_callback_mail, after_callback_sms, after_callback_mail'
  21. def __init__(self, _id, uic, url, callback,
  22. before_callback_sms, before_callback_mail, after_callback_sms, after_callback_mail):
  23. self.id = _id
  24. self.uic = uic ##teams_name
  25. self.url = url
  26. self.callback = callback
  27. self.before_callback_sms = before_callback_sms
  28. self.before_callback_mail = before_callback_mail
  29. self.after_callback_sms = after_callback_sms
  30. self.after_callback_mail = after_callback_mail
  31. def html(self):
  32. if self.url:
  33. return 'curl %s' % self.url
  34. if self.uic:
  35. return 'alarm to %s' % self.uic_href()
  36. return 'do nothing'
  37. def uic_href(self):
  38. if not self.uic:
  39. return ''
  40. arr = self.uic.split(',')
  41. arr = ['<a target="_blank" href="/team/%s/users">%s</a>' % (team, team)
  42. for team in arr]
  43. return ' '.join(arr)
  44. def to_json(self):
  45. return {
  46. 'id': self.id,
  47. 'uic': self.uic,
  48. 'url': self.url,
  49. 'callback': self.callback,
  50. 'before_callback_sms': self.before_callback_sms,
  51. 'before_callback_mail': self.before_callback_mail,
  52. 'after_callback_sms': self.after_callback_sms,
  53. 'after_callback_mail': self.after_callback_mail,
  54. }