From c167444707d23e979beef9cb3ae81e0a5b0b2474 Mon Sep 17 00:00:00 2001 From: "tangshuangpku@hotmail.com" Date: Tue, 7 Jun 2016 02:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/httprest.py | 10 ++++++++++ src/notificationmgr.py | 22 +++++++++++++++++++++- web/templates/base_AdminLTE.html | 21 ++++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/httprest.py b/src/httprest.py index 67cfe50..ec75138 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -599,6 +599,16 @@ def create_notification(cur_user, user, form): result = G_notificationmgr.create_notification(cur_user=cur_user, form=form) return json.dumps(result) + +@app.route("/notification/query_self/", methods=['POST']) +@login_required +def query_self_notifications(cur_user, user, form): + global G_notificationmgr + logger.info("handle request: notification/query_self/") + result = G_notificationmgr.query_self_notifications(cur_user=cur_user, form=form) + return json.dumps(result) + + @app.route("/system/parmList/", methods=['POST']) @login_required def parmList_system(cur_user, user, form): diff --git a/src/notificationmgr.py b/src/notificationmgr.py index b9b67c4..76525c4 100644 --- a/src/notificationmgr.py +++ b/src/notificationmgr.py @@ -2,7 +2,7 @@ import json from log import logger from model import db, Notification, NotificationGroups -from userManager import administration_required +from userManager import administration_required, token_required class NotificationMgr: @@ -53,3 +53,23 @@ class NotificationMgr: 'groups': [group.group_name for group in groups] }) return {'success': 'true', 'data': notify_infos} + + @token_required + def query_self_notifications(self, *args, **kwargs): + user = kwargs['cur_user'] + group_name = user.user_group + notifies = NotificationGroups.query.filter_by(group_name=group_name).all() + notifies.extend(NotificationGroups.query.filter_by(group_name='all').all()) + notify_ids = [notify.notification_id for notify in notifies] + notify_ids = sorted(list(set(notify_ids)), reversed=True) + notify_simple_infos = [] + for notify_id in notify_ids: + notify = Notification.query.filter_by(id=notify_id).first() + if notify.status != 'open': + continue + notify_simple_infos.append({ + 'id': notify.id, + 'title': notify.title, + 'create_date': notify.create_date + }) + return {'success': 'true', 'data': notify_simple_infos} diff --git a/web/templates/base_AdminLTE.html b/web/templates/base_AdminLTE.html index f4db7d1..f19e24d 100644 --- a/web/templates/base_AdminLTE.html +++ b/web/templates/base_AdminLTE.html @@ -55,7 +55,26 @@