blob: d211ad3e7d75f7f667d147c12d1a362a0d9c72b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
from notifications_plugin.models import Notification
class NotificationMiddleware(object):
""" Middleware to get user's notifications """
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.
user = request.user
if user.is_authenticated:
notifications = Notification.objects.get_unread_receiver_notifications(
user.id
).count()
request.custom_notifications = notifications
response = self.get_response(request)
# Code to be executed for each request/response after
# the view is called.
return response
|