diff options
-rw-r--r-- | src/account/views.py | 16 | ||||
-rw-r--r-- | src/templates/account/booking_list.html | 35 |
2 files changed, 45 insertions, 6 deletions
diff --git a/src/account/views.py b/src/account/views.py index 6f390fa..2b4eccb 100644 --- a/src/account/views.py +++ b/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) diff --git a/src/templates/account/booking_list.html b/src/templates/account/booking_list.html index e56b19e..ed59b81 100644 --- a/src/templates/account/booking_list.html +++ b/src/templates/account/booking_list.html @@ -8,7 +8,7 @@ <h3>Booking {{booking.id}}</h3> <ul class="list-group"> <li class="list-group-item">id: {{booking.id}}</li> - <li class="list-group-item">lab: {{booking.resource.template.lab.lab_user.username}}</li> + <li class="list-group-item">lab: {{booking.lab}}</li> <li class="list-group-item">resource: {{booking.resource.template.name}}</li> <li class="list-group-item">start: {{booking.start}}</li> <li class="list-group-item">end: {{booking.end}}</li> @@ -36,7 +36,7 @@ <ul class="list-group"> <li class="list-group-item">id: {{booking.id}}</li> <li class="list-group-item">lab: {{booking.lab}}</li> - <li class="list-group-item">resource: {{booking.resource_name}}</li> + <li class="list-group-item">resource: {{booking.resource.template.name}}</li> <li class="list-group-item">start: {{booking.start}}</li> <li class="list-group-item">end: {{booking.end}}</li> <li class="list-group-item">purpose: {{booking.purpose}}</li> @@ -47,6 +47,28 @@ {% endfor %} </div> + <h2>Expired Bookings + <i class="fa fa-fw fa-caret-down" onclick='toggle_display("expired_bookings");'></i> + </h2> + <div id="expired_bookings" class="card_container" style="display:none;"> + {% for booking in expired_bookings %} + <div class="detail_card"> + <div> + <h3>Booking {{booking.id}}</h3> + <ul class="list-group"> + <li class="list-group-item">id: {{booking.id}}</li> + <li class="list-group-item">lab: {{booking.lab}}</li> + <li class="list-group-item">resource: {{booking.resource.template.name}}</li> + <li class="list-group-item">start: {{booking.start}}</li> + <li class="list-group-item">end: {{booking.end}}</li> + <li class="list-group-item">purpose: {{booking.purpose}}</li> + <li class="list-group-item">owner: {{booking.owner.userprofile.email_addr}}</li> + </ul> + </div> + <a class="btn btn-primary" href="/booking/detail/{{booking.id}}/">Details</a> + </div> + {% endfor %} + </div> <script> var current_booking_id = -1; function cancel_booking(booking_id) { @@ -64,6 +86,15 @@ req.onerror = function() { alert("problem submitting form"); } req.send(formData); } + + function toggle_display(elem_id){ + var e = document.getElementById(elem_id); + if (e.style.display === "none"){ + e.style.display = "grid"; + } else { + e.style.display = "none"; + } + } </script> <div class="modal fade" id="resModal" tabindex="-1" role="dialog" aria-labelledby="my_modal" aria-hidden="true"> <div class="modal-dialog" style="width: 450px;" role="document"> |