actions.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. class ActionItem(object):
  2. def __init__(self, name, text, confirmation, icon, multiple, single, func):
  3. self.name = name
  4. self.text = text or name
  5. self.confirmation = confirmation
  6. self.icon = icon
  7. self.multiple = multiple
  8. self.single = single
  9. self.func = func
  10. def __repr__(self):
  11. return "Action name:%s; text:%s; confirmation:%s; func:%s;" % (
  12. self.name,
  13. self.text,
  14. self.confirmation,
  15. self.func.__name__,
  16. )
  17. def action(name, text, confirmation=None, icon=None, multiple=True, single=True):
  18. """
  19. Use this decorator to expose actions
  20. :param name:
  21. Action name
  22. :param text:
  23. Action text.
  24. :param confirmation:
  25. Confirmation text. If not provided, action will be executed
  26. unconditionally.
  27. :param icon:
  28. Font Awesome icon name
  29. :param multiple:
  30. If true will display action on list view
  31. :param single:
  32. If true will display action on show view
  33. """
  34. def wrap(f):
  35. f._action = (name, text, confirmation, icon, multiple, single)
  36. return f
  37. return wrap