diff options
author | Palaparthy Adityachandra | 2020-05-18 16:28:00 +0530 |
---|---|---|
committer | GitHub | 2020-05-18 16:28:00 +0530 |
commit | 50fec4b15da116fe8af05aa4583d56af27955679 (patch) | |
tree | fe431506e3a89d854f8d0b24e811ca6d6129206a /yaksh/middleware | |
parent | 2db15ac584ae991cd052fa0eed68194594f91775 (diff) | |
parent | f7825eade425cb51ba053763db9d9fd051b0f4ce (diff) | |
download | online_test-50fec4b15da116fe8af05aa4583d56af27955679.tar.gz online_test-50fec4b15da116fe8af05aa4583d56af27955679.tar.bz2 online_test-50fec4b15da116fe8af05aa4583d56af27955679.zip |
Merge pull request #692 from adityacp/merge_monitor_regrade
Merge monitor regrade
Diffstat (limited to 'yaksh/middleware')
-rw-r--r-- | yaksh/middleware/get_notifications.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/yaksh/middleware/get_notifications.py b/yaksh/middleware/get_notifications.py new file mode 100644 index 0000000..d211ad3 --- /dev/null +++ b/yaksh/middleware/get_notifications.py @@ -0,0 +1,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 |