summaryrefslogtreecommitdiffstats
path: root/dashboard/src/account/views.py
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-01-24 10:25:30 -0500
committerParker Berberian <pberberian@iol.unh.edu>2019-02-25 13:38:20 -0500
commit0b06dba533ad66af82785b961dad1fb37e09c94d (patch)
tree29408e39872e40690bcb121a320e830d9c69fa09 /dashboard/src/account/views.py
parent879ebf85275e5f8942eb1a1e30d76cbee2a70715 (diff)
Hides expired bookings in the "My Bookings" Page
This commit hides bookings that have ended from cluttering the "My Bookings" page. Change-Id: I0f98fbff97b1474e73a666aa0000e1923266fafb Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'dashboard/src/account/views.py')
-rw-r--r--dashboard/src/account/views.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/dashboard/src/account/views.py b/dashboard/src/account/views.py
index 6f390fa..2b4eccb 100644
--- a/dashboard/src/account/views.py
+++ b/dashboard/src/account/views.py
@@ -14,6 +14,7 @@ import urllib
import oauth2 as oauth
from django.conf import settings
+from django.utils import timezone
from django.contrib import messages
from django.contrib.auth import logout, authenticate, login
from django.contrib.auth.decorators import login_required
@@ -21,7 +22,6 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.urls import reverse
from django.http import HttpResponse
-from django.utils import timezone
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.views.generic import RedirectView, TemplateView, UpdateView
@@ -198,9 +198,17 @@ def account_booking_view(request):
if not request.user.is_authenticated:
return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
template = "account/booking_list.html"
- bookings = list(Booking.objects.filter(owner=request.user).order_by("-start"))
- collab_bookings = list(request.user.collaborators.all().order_by("-start"))
- context = {"title": "My Bookings", "bookings": bookings, "collab_bookings": collab_bookings}
+ bookings = list(Booking.objects.filter(owner=request.user, end__gt=timezone.now()).order_by("-start"))
+ my_old_bookings = Booking.objects.filter(owner=request.user, end__lt=timezone.now()).order_by("-start")
+ collab_old_bookings = request.user.collaborators.filter(end__lt=timezone.now()).order_by("-start")
+ expired_bookings = list(my_old_bookings.union(collab_old_bookings))
+ collab_bookings = list(request.user.collaborators.filter(end__gt=timezone.now()).order_by("-start"))
+ context = {
+ "title": "My Bookings",
+ "bookings": bookings,
+ "collab_bookings": collab_bookings,
+ "expired_bookings": expired_bookings
+ }
return render(request, template, context=context)