添加新接口

This commit is contained in:
tangshuangpku@hotmail.com 2016-06-06 22:52:34 +08:00
parent c840643289
commit 2758156e0b
5 changed files with 32 additions and 4 deletions

View File

@ -582,6 +582,15 @@ def selfModify_user(cur_user, user, form):
return json.dumps(result)
@app.route("/notification/list/", methods=['POST'])
@login_required
def list_notifications(cur_user, user, form):
global G_notificationmgr
logger.info("handle request: notification/list/")
result = G_notificationmgr.list_notifications(cur_user=cur_user, form=form)
return json.dumps(result)
@app.route("/notification/create/", methods=['POST'])
@login_required
def create_notification(cur_user, user, form):

View File

@ -35,3 +35,16 @@ class NotificationMgr:
db.session.commit()
return {"success": 'true'}
@administration_required
def list_notifications(self, *args, **kwargs):
notifies = Notification.query.all()
notify_infos = []
for notify in notifies:
groups = NotificationGroups.query.filter_by(notification_id=notify.id).all()
notify_infos.append({
'id': notify.id,
'title': notify.title,
'content': notify.content,
'groups': [group.group_name for group in groups]
})
return {'success': 'true', 'data': notify_infos}

View File

@ -141,7 +141,7 @@
<a href='/user/list/'><i class="fa fa-users"></i> <span class="nav-label">Users</span></a>
</li>
<li id="nav_Notification">
<a href='/notification/'><i class="fa fa-envelope"></i> <span class="nav-label">Notification</span></a>
<a href='/notification/'><i class="fa fa-envelope"></i> <span class="nav-label">Notifications</span></a>
</li>
<li id="admin">
<a href='/admin/'><i class="fa fa-gears"></i> <span class="nav-label">Admin</span></a>

View File

@ -1,7 +1,7 @@
{% extends "base_AdminLTE.html" %}
{% block title %}Docklet | Notification{% endblock %}
{% block panel_title %}Notification{% endblock %}
{% block panel_title %}Notifications{% endblock %}
{% block panel_list %}
<ol class="breadcrumb">
@ -9,7 +9,7 @@
<a href="/dashboard/"><i class="fa fa-dashboard"></i>Home</a>
</li>
<li class="active">
<strong>Notification</strong>
<strong>Notifications</strong>
</li>
</ol>
{% endblock %}
@ -34,6 +34,9 @@
<div class="box-body">
<p>test rendering...</p>
{% for title in notification_titles %}
<p>{{ title }}</p>
{% endfor %}
</div>
</div>
</div>

View File

@ -8,7 +8,10 @@ class NotificationView(normalView):
@classmethod
def get(cls):
return cls.render(cls.template_path)
result = dockletRequest.post('/notification/list/')
notifications = result['data']
notification_titles = [notify['title'] for notify in notifications]
return cls.render(cls.template_path, notification_titles=notification_titles)
class CreateNotificationView(normalView):