添加新接口
This commit is contained in:
parent
8344aaa4c4
commit
2360fa94a2
|
@ -600,6 +600,24 @@ def create_notification(cur_user, user, form):
|
|||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/notification/modify/", methods=['POST'])
|
||||
@login_required
|
||||
def modify_notification(cur_user, user, form):
|
||||
global G_notificationmgr
|
||||
logger.info("handle request: notification/modify/")
|
||||
result = G_notificationmgr.modify_notification(cur_user=cur_user, form=form)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/notification/delete/", methods=['POST'])
|
||||
@login_required
|
||||
def delete_notification(cur_user, user, form):
|
||||
global G_notificationmgr
|
||||
logger.info("handle request: notification/delete/")
|
||||
result = G_notificationmgr.delete_notification(cur_user=cur_user, form=form)
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/notification/query_self/", methods=['POST'])
|
||||
@login_required
|
||||
def query_self_notification_simple_infos(cur_user, user, form):
|
||||
|
|
|
@ -65,6 +65,37 @@ class NotificationMgr:
|
|||
})
|
||||
return {'success': 'true', 'data': notify_infos}
|
||||
|
||||
@administration_required
|
||||
def modify_notification(self, *args, **kwargs):
|
||||
form = kwargs['form']
|
||||
notify_id = form['notify_id']
|
||||
notify = Notification.query.filter_by(id=notify_id).first()
|
||||
notify.title = form['title']
|
||||
notify.content = form['content']
|
||||
notify.status = form['status']
|
||||
notifies_groups = NotificationGroups.query.filter_by(notification_id=notify_id).all()
|
||||
for notify_groups in notifies_groups:
|
||||
db.session.delete(notify_groups)
|
||||
group_names = form.getlist('groups')
|
||||
if 'all' in group_names:
|
||||
group_names = ['all']
|
||||
for group_name in group_names:
|
||||
if group_name == 'none':
|
||||
continue
|
||||
notify_groups = NotificationGroups(notify.id, group_name)
|
||||
db.session.add(notify_groups)
|
||||
db.session.commit()
|
||||
return {"success": 'true'}
|
||||
|
||||
@administration_required
|
||||
def delete_notification(self, *args, **kwargs):
|
||||
form = kwargs['form']
|
||||
notify_id = form['notify_id']
|
||||
notify = Notification.query.filter_by(id=notify_id).first()
|
||||
db.session.delete(notify)
|
||||
db.session.commit()
|
||||
return {"success": 'true'}
|
||||
|
||||
@token_required
|
||||
def query_self_notification_simple_infos(self, *args, **kwargs):
|
||||
user = kwargs['cur_user']
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
<small class="font-bold">Edit the details of the notification</small>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="notificationForm" action="/notification/modify/" method="post">
|
||||
<form id="modifyNotificationForm" action="/notification/modify/" method="post">
|
||||
<div class="form-group">
|
||||
<label>Title</label>
|
||||
<input type="text" class="form-control" name="title">
|
||||
|
@ -140,9 +140,25 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="margin-bottom: 0">
|
||||
<label>Status</label>
|
||||
<input type="text" class="form-control" name="N/A" style="display: none" value="N/A">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="radio">
|
||||
{% if 'open' == notify['status'] %}
|
||||
<label><input type="radio" name="status" checked value="open">open</label>
|
||||
<label><input type="radio" name="status" value="closed">closed</label>
|
||||
{% else %}
|
||||
<label><input type="radio" name="status" value="open">open</label>
|
||||
<label><input type="radio" name="status" checked value="closed">closed</label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" onClick="sendModifyNotification();">Save</button>
|
||||
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -182,5 +198,9 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block script_src %}
|
||||
|
||||
<script type="text/javascript">
|
||||
function sendModifyNotification() {
|
||||
$('#modifyNotificationForm').submit();
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
14
web/web.py
14
web/web.py
|
@ -24,7 +24,7 @@ from flask import Flask, request, session, render_template, redirect, send_from_
|
|||
from webViews.dashboard import dashboardView
|
||||
from webViews.user.userlist import userlistView, useraddView, usermodifyView, userdataView, userqueryView
|
||||
from webViews.notification.notification import CreateNotificationView, NotificationView, QuerySelfNotificationsView, \
|
||||
QueryNotificationView
|
||||
QueryNotificationView, ModifyNotificationView, DeleteNotificationView
|
||||
from webViews.user.userinfo import userinfoView
|
||||
from webViews.user.userActivate import userActivateView
|
||||
from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView
|
||||
|
@ -365,6 +365,18 @@ def create_notification():
|
|||
return CreateNotificationView.as_view()
|
||||
|
||||
|
||||
@app.route("/notification/modify/", methods=['POST'])
|
||||
@administration_required
|
||||
def modify_notification():
|
||||
return ModifyNotificationView.as_view()
|
||||
|
||||
|
||||
@app.route("/notification/delete/", methods=['POST'])
|
||||
@administration_required
|
||||
def delete_notification():
|
||||
return DeleteNotificationView.as_view()
|
||||
|
||||
|
||||
@app.route("/notification/query_self/", methods=['POST'])
|
||||
@login_required
|
||||
def query_self_notifications():
|
||||
|
|
|
@ -50,3 +50,16 @@ class QueryNotificationView(normalView):
|
|||
notifies.append(dockletRequest.post('/notification/query/', data={'notify_id': notify_id})['data'])
|
||||
return cls.render(cls.template_path, notifies=notifies)
|
||||
|
||||
|
||||
class ModifyNotificationView(normalView):
|
||||
@classmethod
|
||||
def post(cls):
|
||||
dockletRequest.post('/notification/modify/', request.form)
|
||||
return redirect('/notification/')
|
||||
|
||||
|
||||
class DeleteNotificationView(normalView):
|
||||
@classmethod
|
||||
def post(cls):
|
||||
dockletRequest.post('/notification/delete/', request.form)
|
||||
return redirect('/notification/')
|
||||
|
|
Loading…
Reference in New Issue