Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

67 Zeilen
1.9KB

  1. import json
  2. from flask_classy import FlaskView, route
  3. from modules.core.core import cbpi
  4. class NotificationView(FlaskView):
  5. @route('/', methods=['GET'])
  6. def getMessages(self):
  7. """
  8. Get all Messages
  9. ---
  10. tags:
  11. - notification
  12. responses:
  13. 200:
  14. description: All messages
  15. """
  16. return json.dumps(cbpi.cache["messages"])
  17. @route('/<id>', methods=['DELETE'])
  18. def dismiss(self, id):
  19. """
  20. Delete Message
  21. ---
  22. tags:
  23. - notification
  24. parameters:
  25. - in: path
  26. name: id
  27. schema:
  28. type: integer
  29. required: true
  30. description: Numeric ID of the message
  31. responses:
  32. 200:
  33. description: Message deleted
  34. """
  35. for idx, m in enumerate(cbpi.cache.get("messages", [])):
  36. if (m.get("id") == id):
  37. cbpi.cache["messages"].pop(idx)
  38. return ('', 204)
  39. #@cbpi.event("MESSAGE", async=True)
  40. def messageEvent(message, **kwargs):
  41. """
  42. React on message event. add the message to the cache and push the message to the clients
  43. :param message: the message
  44. :param kwargs: other parameter
  45. :return: None
  46. """
  47. if message["timeout"] is None:
  48. cbpi.cache["messages"].append(message)
  49. cbpi.emit("NOTIFY", message)
  50. @cbpi.addon.core.initializer(order=2)
  51. def init(cbpi):
  52. """
  53. Initializer for the message module
  54. :param app: the flask app
  55. :return: None
  56. """
  57. if cbpi.get_config_parameter("donation_notification", "YES") == "YES":
  58. msg = {"id": len(cbpi.cache["messages"]), "type": "info", "headline": "Support CraftBeerPi with your donation", "message": "You will find the PayPay Donation button in the system menu" , "read": False}
  59. cbpi.cache["messages"].append(msg)
  60. NotificationView.register(cbpi._app, route_base='/api/notification')