diff options
Diffstat (limited to 'src/booking')
-rw-r--r-- | src/booking/urls.py | 4 | ||||
-rw-r--r-- | src/booking/views.py | 84 |
2 files changed, 53 insertions, 35 deletions
diff --git a/src/booking/urls.py b/src/booking/urls.py index c6b9d40..9784fc5 100644 --- a/src/booking/urls.py +++ b/src/booking/urls.py @@ -26,7 +26,6 @@ Including another URLconf 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url -from django.urls import path from booking.views import ( booking_detail_view, @@ -35,12 +34,9 @@ from booking.views import ( BookingListView, ) -from api.views import booking_status - app_name = 'booking' urlpatterns = [ url(r'^detail/(?P<booking_id>[0-9]+)/$', booking_detail_view, name='detail'), - url(r'^detail/(?P<booking_id>[0-9]+)/status$', booking_status, name='detail'), url(r'^(?P<booking_id>[0-9]+)/$', booking_detail_view, name='booking_detail'), url(r'^delete/$', BookingDeleteView.as_view(), name='delete_prefix'), url(r'^delete/(?P<booking_id>[0-9]+)/$', BookingDeleteView.as_view(), name='delete'), 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 - ) |