max number of notifications per user

deletes oldest once surpassed
closes #368
This commit is contained in:
Adarnof 2016-06-10 22:12:39 -04:00 committed by GitHub
parent 94cd0b98d5
commit 01c06cced8

View File

@ -3,7 +3,12 @@ import logging
logger = logging.getLogger(__name__)
MAX_NOTIFICATIONS = 50
def notify(user, title, message=None, level='info'):
if Notification.objects.filter(user=user).count() > MAX_NOTIFICATIONS:
for n in Notification.objects.filter(user=user)[MAX_NOTIFICATIONS:]:
n.delete()
notif = Notification()
notif.user = user
notif.title = title