mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Context processor to count notifications for display in base template Logging handler to generate notifications for users with permission
15 lines
628 B
Python
15 lines
628 B
Python
import logging
|
|
from django.contrib.auth.models import User
|
|
from .models import Notification
|
|
|
|
def NotificationHandler(logging.Handler):
|
|
def emit(self, record):
|
|
for user in User.objects.all():
|
|
if user.has_perm('auth.logging_notifications'):
|
|
notif = Notification()
|
|
notif.user = user
|
|
notif.title = "%s [%s:%s]" % (record.levelname, record.funcName, record.lineno)
|
|
notif.level = str([item[0] for item in Notification.LEVEL_CHOICES if item[1] == record.levelname])
|
|
notif.message = record.getMessage()
|
|
notif.save()
|