1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from django.shortcuts import render
11 from notifier.models import Notification
12 from django.db.models import Q
15 def InboxView(request):
16 if request.user.is_authenticated:
19 return render(request, "dashboard/login.html",
20 {'title': 'Authentication Required'})
22 return render(request,
23 "notifier/inbox.html",
24 {'unread_notifications': Notification.objects.filter(recipients=user.userprofile).order_by('-id').filter(~Q(read_by=user.userprofile)),
25 'read_notifications': Notification.objects.filter(recipients=user.userprofile).order_by('-id').filter(read_by=user.userprofile)})
28 def NotificationView(request, notification_id):
30 if request.user.is_authenticated:
33 return render(request,
34 "dashboard/login.html",
35 {'title': 'Authentication Required'})
37 notification = Notification.objects.get(id=notification_id)
38 if user.userprofile not in notification.recipients.all():
39 return render(request,
40 "dashboard/login.html", {'title': 'Access Denied'})
42 notification.read_by.add(user.userprofile)
44 if request.method == 'POST':
45 if 'delete' in request.POST:
47 notification.recipients.remove(user.userprofile)
48 if not notification.recipients.exists():
53 if 'unread' in request.POST:
54 notification.read_by.remove(user.userprofile)
57 return render(request,
58 "notifier/notification.html", {'notification': notification})