aboutsummaryrefslogtreecommitdiffstats
path: root/src/notifier/views.py
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-02-25 17:04:57 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-02-25 17:04:57 +0000
commite858a658aa9594949ec3b357253b34c7489d623d (patch)
tree09acd4000e3de9c7a064a267dffe2986b3e4af41 /src/notifier/views.py
parentb06649b237636f8fd29947094e9fc44472b88d18 (diff)
parentde9a0666a8856e42d227754f6dc3915f6928af4c (diff)
Merge "Update Inbox Featureset"
Diffstat (limited to 'src/notifier/views.py')
-rw-r--r--src/notifier/views.py39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/notifier/views.py b/src/notifier/views.py
index 4ee757f..3a85eda 100644
--- a/src/notifier/views.py
+++ b/src/notifier/views.py
@@ -7,27 +7,52 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from notifier.models import Notification
from django.shortcuts import render
+from notifier.models import Notification
+from django.db.models import Q
def InboxView(request):
if request.user.is_authenticated:
user = request.user
else:
- return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
+ return render(request, "dashboard/login.html",
+ {'title': 'Authentication Required'})
- return render(request, "notifier/inbox.html", {'notifications': Notification.objects.filter(recipients=user.userprofile)})
+ return render(request,
+ "notifier/inbox.html",
+ {'unread_notifications': Notification.objects.filter(recipients=user.userprofile).order_by('-id').filter(~Q(read_by=user.userprofile)),
+ 'read_notifications': Notification.objects.filter(recipients=user.userprofile).order_by('-id').filter(read_by=user.userprofile)})
def NotificationView(request, notification_id):
+
if request.user.is_authenticated:
user = request.user
else:
- return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
+ return render(request,
+ "dashboard/login.html",
+ {'title': 'Authentication Required'})
notification = Notification.objects.get(id=notification_id)
if user.userprofile not in notification.recipients.all():
- return render(request, "dashboard/login.html", {'title': 'Access Denied'})
-
- return render(request, "notifier/notification.html", {'notification': notification})
+ return render(request,
+ "dashboard/login.html", {'title': 'Access Denied'})
+
+ notification.read_by.add(user.userprofile)
+ notification.save()
+ if request.method == 'POST':
+ if 'delete' in request.POST:
+ # handle deleting
+ notification.recipients.remove(user.userprofile)
+ if not notification.recipients.exists():
+ notification.delete()
+ else:
+ notification.save()
+
+ if 'unread' in request.POST:
+ notification.read_by.remove(user.userprofile)
+ notification.save()
+
+ return render(request,
+ "notifier/notification.html", {'notification': notification})