aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/forms.py
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-05-31 20:01:57 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-05-31 20:01:57 +0000
commitbe541f2ae9e8415a156f3dc7f6796e7c90749181 (patch)
tree949cb518d8a0fb59244e750992e6752cac751a95 /src/booking/forms.py
parent6b8115d7ac8412c9d0ba6899062969b636ed9149 (diff)
parent63bec7d84cbf1acd3a9a357b58b47584b1701229 (diff)
Merge "Refactor selector step logic"
Diffstat (limited to 'src/booking/forms.py')
-rw-r--r--src/booking/forms.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/booking/forms.py b/src/booking/forms.py
index de427ab..e48b293 100644
--- a/src/booking/forms.py
+++ b/src/booking/forms.py
@@ -10,12 +10,13 @@ import django.forms as forms
from django.forms.widgets import NumberInput
from workflow.forms import (
- SearchableSelectMultipleWidget,
MultipleSelectFilterField,
MultipleSelectFilterWidget,
FormUtils)
from account.models import UserProfile
from resource_inventory.models import Image, Installer, Scenario
+from workflow.forms import SearchableSelectMultipleField
+from booking.lib import get_user_items, get_user_field_opts
class QuickBookingForm(forms.Form):
@@ -27,16 +28,11 @@ class QuickBookingForm(forms.Form):
scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False)
def __init__(self, data=None, user=None, *args, **kwargs):
- chosen_users = []
if "default_user" in kwargs:
default_user = kwargs.pop("default_user")
else:
default_user = "you"
self.default_user = default_user
- if "chosen_users" in kwargs:
- chosen_users = kwargs.pop("chosen_users")
- elif data and "users" in data:
- chosen_users = data.getlist("users")
super(QuickBookingForm, self).__init__(data=data, **kwargs)
@@ -44,12 +40,13 @@ class QuickBookingForm(forms.Form):
Image.objects.filter(public=True) | Image.objects.filter(owner=user)
)
- self.fields['users'] = forms.CharField(
- widget=SearchableSelectMultipleWidget(
- attrs=self.build_search_widget_attrs(chosen_users, default_user=default_user)
- ),
- required=False
+ self.fields['users'] = SearchableSelectMultipleField(
+ queryset=UserProfile.objects.select_related('user').exclude(user=user),
+ items=get_user_items(exclude=user),
+ required=False,
+ **get_user_field_opts()
)
+
attrs = FormUtils.getLabData(0)
attrs['selection_data'] = 'false'
self.fields['filter_field'] = MultipleSelectFilterField(widget=MultipleSelectFilterWidget(attrs=attrs))