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 opsys.label = "Operating System"
25 installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False)
26 scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False)
28 class BookingEditForm(forms.Form):
29 fields = ['start', 'end', 'purpose', 'opsys', 'reset', 'installer', 'scenario']
31 start = forms.DateTimeField()
32 end = forms.DateTimeField()
33 purpose = forms.CharField(max_length=300)
34 opsys = forms.ModelChoiceField(queryset=Opsys.objects.all(), required=False)
35 installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False)
36 scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=False)
37 reset = forms.ChoiceField(choices = ((True, 'Yes'),(False, 'No')), label="Reset System", initial='False', required=True)
40 def __init__(self, *args, **kwargs ):
42 cloned_kwargs['purpose'] = kwargs.pop('purpose')
43 cloned_kwargs['start'] = kwargs.pop('start')
44 cloned_kwargs['end'] = kwargs.pop('end')
45 if 'installer' in kwargs:
46 cloned_kwargs['installer'] = kwargs.pop('installer')
47 if 'scenario' in kwargs:
48 cloned_kwargs['scenario'] = kwargs.pop('scenario')
49 super(BookingEditForm, self).__init__( *args, **kwargs)
51 self.fields['purpose'].initial = cloned_kwargs['purpose']
52 self.fields['start'].initial = cloned_kwargs['start'].strftime('%m/%d/%Y %H:%M')
53 self.fields['end'].initial = cloned_kwargs['end'].strftime('%m/%d/%Y %H:%M')
55 self.fields['installer'].initial = cloned_kwargs['installer'].id
58 except AttributeError:
61 self.fields['scenario'].initial = cloned_kwargs['scenario'].id
64 except AttributeError: