First Version

This commit is contained in:
Manuel83
2017-06-11 17:12:22 +02:00
parent b03966562c
commit 58e927b0bf
57 changed files with 8540 additions and 1 deletions
+52
View File
@@ -0,0 +1,52 @@
import json
from flask_classy import FlaskView, route
from modules import cbpi
class NotificationView(FlaskView):
@route('/', methods=['GET'])
def getMessages(self):
"""
Get all messages
:return: current messages
"""
return json.dumps(cbpi.cache["messages"])
@route('/<id>', methods=['DELETE'])
def dismiss(self, id):
"""
Delete message from cache by id
:param id: message id to be deleted
:return: empty response HTTP 204
"""
for idx, m in enumerate(cbpi.cache.get("messages", [])):
if (m.get("id") == id):
cbpi.cache["messages"].pop(idx)
return ('', 204)
@cbpi.event("MESSAGE", async=True)
def messageEvent(message, **kwargs):
"""
React on message event. add the message to the cache and push the message to the clients
:param message: the message
:param kwargs: other parameter
:return: None
"""
msg = {"id": len(cbpi.cache["messages"]), "type": "info", "message": message, "read": False}
cbpi.cache["messages"].append(msg)
cbpi.emit('MESSAGE', msg,)
@cbpi.initalizer(order=2)
def init(cbpi):
"""
Initializer for the message module
:param app: the flask app
:return: None
"""
print "INITIALIZE MESSAGE MODULE"
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}
cbpi.cache["messages"].append(msg)
NotificationView.register(cbpi.app, route_base='/api/notification')