添加新接口

This commit is contained in:
tangshuangpku@hotmail.com 2016-06-06 19:44:45 +08:00
parent c3e9fcbb22
commit 662f3ed89a
1 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import json
from log import logger from log import logger
from model import db, Notification, NotificationGroups from model import db, Notification, NotificationGroups
from userManager import administration_required from userManager import administration_required
@ -20,13 +22,14 @@ class NotificationMgr:
def create_notification(self, *args, **kwargs): def create_notification(self, *args, **kwargs):
''' '''
Usage: createNotification(cur_user = 'Your current user', form = 'Post form') Usage: createNotification(cur_user = 'Your current user', form = 'Post form')
Post form: {title: 'Your title', content: 'Your content', groups: ['groupA', 'groupB']} Post form: {title: 'Your title', content: 'Your content', groups: "['groupA', 'groupB']"}
''' '''
form = kwargs['form'] form = kwargs['form']
notify = Notification(form['title'], form['content']) notify = Notification(form['title'], form['content'])
db.session.add(notify) db.session.add(notify)
db.session.commit() db.session.commit()
for group_name in form['groups']: groups = json.loads(form['groups'])
for group_name in groups:
notify_groups = NotificationGroups(notify.id, group_name) notify_groups = NotificationGroups(notify.id, group_name)
db.session.add(notify_groups) db.session.add(notify_groups)
db.session.commit() db.session.commit()