From d0aecd0ee59663ac81733ff8087847106c7ba4cc Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 9 Jul 2020 04:16:45 +0100 Subject: Rename triggerNotif to addNotification, add array support --- app/utils.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'app/utils.py') diff --git a/app/utils.py b/app/utils.py index d6e6eaa..67b4015 100644 --- a/app/utils.py +++ b/app/utils.py @@ -188,12 +188,19 @@ def is_package_page(f): return decorated_function -def triggerNotif(owner, causer, title, url): - if owner.rank.atLeast(UserRank.NEW_MEMBER) and owner != causer: - Notification.query.filter_by(user=owner, causer=causer, title=title, url=url).delete() - notif = Notification(owner, causer, title, url) + +def addNotification(target, causer, title, url): + if not isinstance(target, User): + for x in target: + addNotification(x, causer, title, url) + return + + if target.rank.atLeast(UserRank.NEW_MEMBER) and target != causer: + Notification.query.filter_by(user=target, causer=causer, title=title, url=url).delete() + notif = Notification(target, causer, title, url) db.session.add(notif) + def clearNotifications(url): if current_user.is_authenticated: Notification.query.filter_by(user=current_user, url=url).delete() -- cgit v1.2.3