ISO-27001-Risk-Management/risks/context_processors.py

14 lines
592 B
Python
Raw Normal View History

# ---------------------------------------------------------------------------
# unread_notifications_count()
# ---------------------------------------------------------------------------
def unread_notifications_count(request):
"""
Context processor:
Returns the number of unread notifications for the current user.
"""
if not request.user.is_authenticated:
return {"notifications_unread_count": 0}
from .models import Notification
count = Notification.objects.filter(user=request.user, read=False).count()
return {"notifications_unread_count": count}