aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/views.py
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-09-27 17:03:38 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-10-19 18:10:17 -0400
commitaff53e072502d63d8002d9c83213ce7f9d12c352 (patch)
tree3a30adca1fe7c958ddc092dbf7b9fa24259dd923 /src/booking/views.py
parent1947d40115c7b13f8617ea92078a6f910d6bc799 (diff)
user subsystem clean up
Change-Id: Ia59bb7c1e4412693f55cdcaf9607bcb4158850ae Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/booking/views.py')
-rw-r--r--src/booking/views.py84
1 files changed, 53 insertions, 31 deletions
diff --git a/src/booking/views.py b/src/booking/views.py
index df446d5..4fdd1db 100644
--- a/src/booking/views.py
+++ b/src/booking/views.py
@@ -9,18 +9,17 @@
##############################################################################
from django.contrib import messages, admin
+import json
+from django.contrib import messages
from django.shortcuts import get_object_or_404
-from django.http import JsonResponse, HttpResponse
from django.utils import timezone
-from django.views import View
from django.views.generic import TemplateView
from django.shortcuts import redirect, render
-from django.db.models import Q
-from django.urls import reverse
from account.models import Downtime, Lab
-from api.views import get_booking_status
from booking.models import Booking
+from liblaas.views import booking_booking_status
+from django.http import HttpResponse, JsonResponse
class BookingView(TemplateView):
template_name = "booking/booking_detail.html"
@@ -71,30 +70,53 @@ class BookingListView(TemplateView):
def booking_detail_view(request, booking_id):
- user = None
- if request.user.is_authenticated:
- user = request.user
- else:
- return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
+ if request.method == 'GET':
+ user = None
+ if request.user.is_authenticated:
+ user = request.user
+ else:
+ return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
+
+ booking = get_object_or_404(Booking, id=booking_id)
+ statuses = []
+ if booking.aggregateId:
+ statuses = booking_booking_status(booking.aggregateId)
+ allowed_users = set(list(booking.collaborators.all()))
+ if (request.user.is_superuser):
+ allowed_users.add(request.user)
+ allowed_users.add(booking.owner)
+ if user not in allowed_users:
+ return render(request, "dashboard/login.html", {'title': 'This page is private'})
+
+ context = {
+ 'title': 'Booking Details',
+ 'booking': booking,
+ 'status': statuses,
+ 'collab_string': ', '.join(map(str, booking.collaborators.all()))
+ }
+
+ return render(
+ request,
+ "booking/booking_detail.html",
+ context
+ )
+
+ if request.method == 'POST':
+ return update_booking_status(request)
+
+ return HttpResponse(status=405)
+
+def update_booking_status(request):
+ if request.method != "POST":
+ return HttpResponse(status=405)
+
+ data = json.loads(request.body.decode('utf-8'))
+ agg_id = data["agg_id"]
+
+ response = booking_booking_status(agg_id)
+
+ if (response.status_code == 200):
+ return JsonResponse(status=200, data=response)
+
+ return HttpResponse(status=500)
- booking = get_object_or_404(Booking, id=booking_id)
- statuses = get_booking_status(booking)
- allowed_users = set(list(booking.collaborators.all()))
- if (request.user.is_superuser):
- allowed_users.add(request.user)
- allowed_users.add(booking.owner)
- if user not in allowed_users:
- return render(request, "dashboard/login.html", {'title': 'This page is private'})
- context = {
- 'title': 'Booking Details',
- 'booking': booking,
- 'status': statuses,
- 'collab_string': ', '.join(map(str, booking.collaborators.all())),
- 'contact_email': booking.lab.contact_email
- }
-
- return render(
- request,
- "booking/booking_detail.html",
- context
- )