diff options
author | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2018-01-05 16:07:13 -0500 |
---|---|---|
committer | Sawyer Bergeron <sbergeron@iol.unh.edu> | 2018-01-09 15:03:34 -0500 |
commit | a1df798486c60c911dfb2e6c2c487f7bcb7f6d01 (patch) | |
tree | 60bec95b5de53c332ab1101240095940e5a4554b /src/booking/forms.py | |
parent | c81da17a046f1ad81f05de8a242b14ec02cf7c9a (diff) |
Implement Booking Modification Interface
Jira: PHAROS-330
Users can change start date if it has not already occurred, and
can change end date, purpose, and both installer and scenario.
Standard checks apply similar to when initially creating a booking.
Change-Id: Ibae7fe91a58bd6e0741db065265c05c3823bdc27
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/booking/forms.py')
-rw-r--r-- | src/booking/forms.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/booking/forms.py b/src/booking/forms.py index 1f09c05..b4acd8f 100644 --- a/src/booking/forms.py +++ b/src/booking/forms.py @@ -11,10 +11,21 @@ import django.forms as forms from booking.models import Installer, Scenario, Opsys - +from datetime import datetime class BookingForm(forms.Form): - fields = ['start', 'end', 'purpose', 'opsys', 'installer', 'scenario'] + fields = ['start', 'end', 'purpose', 'opsys', 'reset', 'installer', 'scenario'] + + start = forms.DateTimeField() + end = forms.DateTimeField() + reset = forms.ChoiceField(choices = ((True, 'Yes'),(False, 'No')), label="Reset System", initial='False', required=False) + purpose = forms.CharField(max_length=300) + opsys = forms.ModelChoiceField(queryset=Opsys.objects.all(), required=False) + installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False) + scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False) + +class BookingEditForm(forms.Form): + fields = ['start', 'end', 'purpose', 'opsys', 'reset', 'installer', 'scenario'] start = forms.DateTimeField() end = forms.DateTimeField() @@ -22,3 +33,32 @@ class BookingForm(forms.Form): opsys = forms.ModelChoiceField(queryset=Opsys.objects.all(), required=False) installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False) scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False) + reset = forms.ChoiceField(choices = ((True, 'Yes'),(False, 'No')), label="Reset System", initial='False', required=True) + + + def __init__(self, *args, **kwargs ): + cloned_kwargs = {} + cloned_kwargs['purpose'] = kwargs.pop('purpose') + cloned_kwargs['start'] = kwargs.pop('start') + cloned_kwargs['end'] = kwargs.pop('end') + if 'installer' in kwargs: + cloned_kwargs['installer'] = kwargs.pop('installer') + if 'scenario' in kwargs: + cloned_kwargs['scenario'] = kwargs.pop('scenario') + super(BookingEditForm, self).__init__( *args, **kwargs) + + self.fields['purpose'].initial = cloned_kwargs['purpose'] + self.fields['start'].initial = cloned_kwargs['start'].strftime('%m/%d/%Y %H:%M') + self.fields['end'].initial = cloned_kwargs['end'].strftime('%m/%d/%Y %H:%M') + try: + self.fields['installer'].initial = cloned_kwargs['installer'].id + except KeyError: + pass + except AttributeError: + pass + try: + self.fields['scenario'].initial = cloned_kwargs['scenario'].id + except KeyError: + pass + except AttributeError: + pass |