添加新接口

This commit is contained in:
tangshuangpku@hotmail.com 2016-06-07 16:21:32 +08:00
parent 3f30b796c6
commit ae71f8e695
9 changed files with 119 additions and 14 deletions

View File

@ -609,6 +609,15 @@ def query_self_notifications(cur_user, user, form):
return json.dumps(result)
@app.route("/notification/query/", methods=['POST'])
@login_required
def query_notification(cur_user, user, form):
global G_notificationmgr
logger.info("handle request: notification/query/")
result = G_notificationmgr.query_notification(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):

View File

@ -40,7 +40,7 @@ def initlogging(name='docklet'):
logger.setLevel(LOG_LEVEL)
# Make a handler that writes to a file, making a new file at midnight and keeping 3 backups
handler = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME,
when="midnight", backupCount=LOG_LIFE)
when="midnight", backupCount=LOG_LIFE, encoding='utf-8')
# Format each log message like this
formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(module)s[%(lineno)d] %(message)s')
# Attach the formatter to the handler

View File

@ -62,14 +62,38 @@ class NotificationMgr:
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)), reverse=True)
notify_simple_infos = []
notify_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({
notify_infos.append({
'id': notify.id,
'title': notify.title,
'content': notify.content,
'create_date': notify.create_date
})
return {'success': 'true', 'data': notify_simple_infos}
return {'success': 'true', 'data': notify_infos}
@token_required
def query_notification(self, *args, **kwargs):
user = kwargs['cur_user']
form = kwargs['form']
group_name = user.user_group
notify_id = form['notify_id']
groups = NotificationGroups.query.filter_by(notification_id=notify_id).all()
if not(group_name in [group.group_name for group in groups]):
if not('all' in [group.group_name for group in groups]):
return {'success': 'false', 'reason': 'Unauthorized Action'}
notify = Notification.query.filter_by(id=notify_id).first()
notify_info = {
'id': notify.id,
'title': notify.title,
'content': notify.content,
'create_date': notify.create_date
}
if notify.status != 'open':
notify_info['title'] = 'This notification is not available'
notify_info['content'] = 'Sorry, it seems that the administrator has closed this notification.'
return {'success': 'false', 'data': notify_info}
return {'success': 'true', 'data': notify_info}

View File

@ -58,18 +58,18 @@
<li class="dropdown notifications-menu">
<a id='notificationIcon' href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<span class="label label-warning">0</span>
{# <span class="label label-warning">0</span>#}
</a>
<ul class="dropdown-menu">
<li id="notificationHeader" class="header">You have 0 notifications</li>
<li>
<!-- inner menu: contains the actual data -->
<ul id='notificationList' class="menu">
<li>
<a href="#">
<i class="fa fa-envelop"></i> Notification title
</a>
</li>
{# <li>#}
{# <a href="#">#}
{# <i class="fa fa-envelop"></i> Notification title#}
{# </a>#}
{# </li>#}
</ul>
</li>
<li class="footer"><a href="#">View all</a></li>
@ -271,7 +271,7 @@
for(var i = 0; i < cnt; i++) {
var notify = notifies[i];
console.log(notify);
var a = $("<a href=\"/notification/detail/"+ notify.id +"/\"><i class=\"fa fa-envelop\"></i> "+ notify.title +"</a>")
var a = $("<a href=\"/notification/detail/"+ notify.id +"/\"><i class=\"fa fa-envelope\"></i> "+ notify.title +"</a>")
var item = $("<li></li>");
item.append(a);
$("#notificationList").append(item);

View File

@ -51,7 +51,7 @@
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Groups</label>
<div class="col-sm-10">
<div class="checkbox col-sm-10">
<input type="checkbox" checked name="groups" value="none" style="display: none">
<input type="checkbox" name="groups" value="all">all&nbsp;&nbsp;
{% for group_name in groups %}

View File

@ -0,0 +1,50 @@
{% extends "base_AdminLTE.html" %}
{% block title %}Docklet | Notification{% endblock %}
{% block panel_title %}Notifications{% endblock %}
{% block panel_list %}
<ol class="breadcrumb">
<li>
<a href="/dashboard/"><i class="fa fa-dashboard"></i>Home</a>
</li>
<li class="active">
<strong>Notifications</strong>
</li>
</ol>
{% endblock %}
{##}
{% block content %}
{% for notify in notifies %}
<div class="row">
<div class="col-lg-12">
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">{{ notify['title'] }}</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-widget="remove">
<i class="fa fa-times"></i>
</button>
</div>
</div>
<div class="box-body">
{{ notify['content'] }}
</div>
<div class="box-footer">
{{ notify['create_date'] }}
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
{% block script_src %}
{% endblock %}

View File

@ -23,7 +23,8 @@ from webViews.log import logger
from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort
from webViews.dashboard import dashboardView
from webViews.user.userlist import userlistView, useraddView, usermodifyView, userdataView, userqueryView
from webViews.notification.notification import CreateNotificationView, NotificationView, QuerySelfNotificationsView
from webViews.notification.notification import CreateNotificationView, NotificationView, QuerySelfNotificationsView, \
QueryNotificationView
from webViews.user.userinfo import userinfoView
from webViews.user.userActivate import userActivateView
from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView
@ -369,6 +370,13 @@ def create_notification():
def query_self_notifications():
return QuerySelfNotificationsView.as_view()
@app.route("/notification/detail/<notify_id>/", methods=['GET'])
@login_required
def query_notification_detail(notify_id):
return QueryNotificationView.get_by_id(notify_id)
@app.route("/system/modify/", methods=['POST'])
@administration_required
def systemmodify():

View File

@ -45,7 +45,7 @@ def initlogging(name='docklet'):
logger.setLevel(LOG_LEVEL)
# Make a handler that writes to a file, making a new file at midnight and keeping 3 backups
handler = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME,
when="midnight", backupCount=0)
when="midnight", backupCount=0, encoding='utf-8')
# Format each log message like this
formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(module)s[%(lineno)d] %(message)s')
# Attach the formatter to the handler

View File

@ -36,3 +36,17 @@ class QuerySelfNotificationsView(normalView):
def post(cls):
result = dockletRequest.post('/notification/query_self/')
return json.dumps(result)
class QueryNotificationView(normalView):
template_path = 'notification_info.html'
@classmethod
def get_by_id(cls, notify_id):
notifies = []
if notify_id == 'all':
notifies.extend(dockletRequest.post('/notification/query_self/')['data'])
else:
notifies.append(dockletRequest.post('/notification/query/', data={'notify_id': notify_id})['data'])
return cls.render(cls.template_path, notifies=notifies)