aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/quick_deployer.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/booking/quick_deployer.py')
-rw-r--r--src/booking/quick_deployer.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/booking/quick_deployer.py b/src/booking/quick_deployer.py
index 763c8a0..0e0cc5a 100644
--- a/src/booking/quick_deployer.py
+++ b/src/booking/quick_deployer.py
@@ -12,7 +12,6 @@ import json
import uuid
import re
from django.db.models import Q
-from django.contrib.auth.models import User
from datetime import timedelta
from django.utils import timezone
from account.models import Lab
@@ -97,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)
+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['hosts'][0]
- profile_id = list(host_dict.keys())[0]
- profile_id = int(profile_id.split("_")[-1])
- profile = HostProfile.objects.get(id=profile_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'])
- # check validity of field data before trying to apply to models
- if len(host_json['labs']) != 1:
+ 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
@@ -321,12 +317,8 @@ def create_from_form(form, request):
)
booking.pdf = PDFTemplater.makePDF(booking)
- users_field = users_field[2:-2]
- if users_field: # may be empty after split, if no collaborators entered
- users_field = json.loads(users_field)
- for collaborator in users_field:
- user = User.objects.get(id=collaborator['id'])
- booking.collaborators.add(user)
+ for collaborator in users_field: # list of UserProfiles
+ booking.collaborators.add(collaborator.user)
booking.save()
@@ -334,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 = {}