aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking
diff options
context:
space:
mode:
Diffstat (limited to 'src/booking')
-rw-r--r--src/booking/forms.py3
-rw-r--r--src/booking/quick_deployer.py35
-rw-r--r--src/booking/views.py12
3 files changed, 24 insertions, 26 deletions
diff --git a/src/booking/forms.py b/src/booking/forms.py
index e48b293..df88cc6 100644
--- a/src/booking/forms.py
+++ b/src/booking/forms.py
@@ -48,8 +48,7 @@ class QuickBookingForm(forms.Form):
)
attrs = FormUtils.getLabData(0)
- attrs['selection_data'] = 'false'
- self.fields['filter_field'] = MultipleSelectFilterField(widget=MultipleSelectFilterWidget(attrs=attrs))
+ self.fields['filter_field'] = MultipleSelectFilterField(widget=MultipleSelectFilterWidget(**attrs))
self.fields['length'] = forms.IntegerField(
widget=NumberInput(
attrs={
diff --git a/src/booking/quick_deployer.py b/src/booking/quick_deployer.py
index ac69c8c..0e0cc5a 100644
--- a/src/booking/quick_deployer.py
+++ b/src/booking/quick_deployer.py
@@ -96,25 +96,22 @@ class BookingPermissionException(Exception):
pass
-def parse_host_field(host_field_contents):
- host_json = json.loads(host_field_contents)
- lab_dict = host_json['labs'][0]
- lab_id = list(lab_dict.keys())[0]
- lab_user_id = int(lab_id.split("_")[-1])
- lab = Lab.objects.get(lab_user__id=lab_user_id)
-
- host_dict = host_json['hosts'][0]
- profile_id = list(host_dict.keys())[0]
- profile_id = int(profile_id.split("_")[-1])
- profile = HostProfile.objects.get(id=profile_id)
-
- # check validity of field data before trying to apply to models
- if len(host_json['labs']) != 1:
+def parse_host_field(host_json):
+ lab, profile = (None, None)
+ lab_dict = host_json['lab']
+ for lab_info in lab_dict.values():
+ if lab_info['selected']:
+ lab = Lab.objects.get(lab_user__id=lab_info['id'])
+
+ host_dict = host_json['host']
+ for host_info in host_dict.values():
+ if host_info['selected']:
+ profile = HostProfile.objects.get(pk=host_info['id'])
+
+ if lab is None:
raise NoLabSelectedError("No lab was selected")
- if not lab:
- raise LabDNE("Lab with provided ID does not exist")
- if not profile:
- raise HostProfileDNE("Host type with provided ID does not exist")
+ if profile is None:
+ raise HostProfileDNE("No Host was selected")
return lab, profile
@@ -329,6 +326,8 @@ def create_from_form(form, request):
JobFactory.makeCompleteJob(booking)
NotificationHandler.notify_new_booking(booking)
+ return booking
+
def drop_filter(user):
installer_filter = {}
diff --git a/src/booking/views.py b/src/booking/views.py
index 13e9d01..bad7dc9 100644
--- a/src/booking/views.py
+++ b/src/booking/views.py
@@ -16,6 +16,7 @@ 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 resource_inventory.models import ResourceBundle, HostProfile, Image, Host
from resource_inventory.resource_manager import ResourceManager
@@ -60,14 +61,13 @@ def quick_create(request):
if form.is_valid():
try:
- create_from_form(form, request)
+ booking = create_from_form(form, request)
+ messages.success(request, "We've processed your request. "
+ "Check Account->My Bookings for the status of your new booking")
+ return redirect(reverse('booking:booking_detail', kwargs={'booking_id': booking.id}))
except Exception as e:
messages.error(request, "Whoops, an error occurred: " + str(e))
- return render(request, 'workflow/exit_redirect.html', context)
-
- messages.success(request, "We've processed your request. "
- "Check Account->My Bookings for the status of your new booking")
- return render(request, 'workflow/exit_redirect.html', context)
+ return render(request, 'booking/quick_deploy.html', context)
else:
messages.error(request, "Looks like the form didn't validate. Check that you entered everything correctly")
return render(request, 'booking/quick_deploy.html', context)