mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Use a Q query to identify users for logging notifications. Should be much faster. http://stackoverflow.com/questions/378303/how-to-get-a-list-of-all-users-with-a-specific-permission-group-in-django Closes #576
23 lines
623 B
Python
23 lines
623 B
Python
from __future__ import unicode_literals
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
MAX_NOTIFICATIONS = 50
|
|
|
|
|
|
def notify(user, title, message=None, level='info'):
|
|
from .models import Notification
|
|
if Notification.objects.filter(user=user).count() > MAX_NOTIFICATIONS:
|
|
for n in Notification.objects.filter(user=user)[MAX_NOTIFICATIONS-1:]:
|
|
n.delete()
|
|
notif = Notification()
|
|
notif.user = user
|
|
notif.title = title
|
|
if not message:
|
|
message = title
|
|
notif.message = message
|
|
notif.level = level
|
|
notif.save()
|
|
logger.info("Created notification %s" % notif)
|