1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 import django.forms as forms
13 from booking.models import Installer, Scenario, Opsys
14 from datetime import datetime
16 class BookingForm(forms.Form):
17 fields = ['start', 'end', 'purpose', 'opsys', 'reset', 'installer', 'scenario']
19 start = forms.DateTimeField()
20 end = forms.DateTimeField()
21 reset = forms.ChoiceField(choices = ((True, 'Yes'),(False, 'No')), label="Reset System", initial='False', required=False)
22 purpose = forms.CharField(max_length=300)
23 opsys = forms.ModelChoiceField(queryset=Opsys.objects.all(), required=False)
24 installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False)
25 scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False)
27 class BookingEditForm(forms.Form):
28 fields = ['start', 'end', 'purpose', 'opsys', 'reset', 'installer', 'scenario']
30 start = forms.DateTimeField()
31 end = forms.DateTimeField()
32 purpose = forms.CharField(max_length=300)
33 opsys = forms.ModelChoiceField(queryset=Opsys.objects.all(), required=False)
34 installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False)
35 scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False)
36 reset = forms.ChoiceField(choices = ((True, 'Yes'),(False, 'No')), label="Reset System", initial='False', required=True)
39 def __init__(self, *args, **kwargs ):
41 cloned_kwargs['purpose'] = kwargs.pop('purpose')
42 cloned_kwargs['start'] = kwargs.pop('start')
43 cloned_kwargs['end'] = kwargs.pop('end')
44 if 'installer' in kwargs:
45 cloned_kwargs['installer'] = kwargs.pop('installer')
46 if 'scenario' in kwargs:
47 cloned_kwargs['scenario'] = kwargs.pop('scenario')
48 super(BookingEditForm, self).__init__( *args, **kwargs)
50 self.fields['purpose'].initial = cloned_kwargs['purpose']
51 self.fields['start'].initial = cloned_kwargs['start'].strftime('%m/%d/%Y %H:%M')
52 self.fields['end'].initial = cloned_kwargs['end'].strftime('%m/%d/%Y %H:%M')
54 self.fields['installer'].initial = cloned_kwargs['installer'].id
57 except AttributeError:
60 self.fields['scenario'].initial = cloned_kwargs['scenario'].id
63 except AttributeError: