diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2019-06-21 15:11:37 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2019-06-21 15:11:37 +0000 |
commit | 16e270ab8a432e98e556488a2d593724a1dea12d (patch) | |
tree | 375fd80c727e01e5343e4caa7ee730b0d90c4b6e /src/booking | |
parent | 2036a3cf0c3316670fa1a5b06ff57d41195b0de9 (diff) | |
parent | 46ab5d82161a4a6ee368dc2adf6e0ca0dea38799 (diff) |
Merge "Redesigns Multiple Select Filter Widget"
Diffstat (limited to 'src/booking')
-rw-r--r-- | src/booking/forms.py | 3 | ||||
-rw-r--r-- | src/booking/quick_deployer.py | 33 |
2 files changed, 16 insertions, 20 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..11f5437 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 |