summaryrefslogtreecommitdiffstats
path: root/pharos-dashboard/dashboard/forms/booking_form.py
diff options
context:
space:
mode:
authormaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:10:31 +0200
committermaxbr <maxbr@mi.fu-berlin.de>2016-08-19 17:10:31 +0200
commit79aec84973032e15ae9d36fcbd7d7d42af3283d1 (patch)
treec02fbd44cd53b0eed105bc648c743b10c62bfeb4 /pharos-dashboard/dashboard/forms/booking_form.py
parent639cd5db77064c275253828780c17ae59551d95c (diff)
Split the dashboard into different apps, add tests
JIRA: RELENG-12 Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/dashboard/forms/booking_form.py')
-rw-r--r--pharos-dashboard/dashboard/forms/booking_form.py37
1 files changed, 0 insertions, 37 deletions
diff --git a/pharos-dashboard/dashboard/forms/booking_form.py b/pharos-dashboard/dashboard/forms/booking_form.py
deleted file mode 100644
index 9cf8048..0000000
--- a/pharos-dashboard/dashboard/forms/booking_form.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from dashboard.models import Booking
-import django.forms as forms
-from django.utils.translation import ugettext_lazy as _
-
-
-class BookingForm(forms.ModelForm):
- class Meta:
- model = Booking
- fields = ['start_date_time', 'end_date_time', 'purpose', 'booking_id']
-
- PURPOSE = {
- 'id': 'purposefield',
- 'type': 'text',
- 'placeholder': 'Booking purpose',
- }
-
- widgets = {
- 'purpose': forms.TextInput(attrs=PURPOSE),
- }
-
- # DATETIMEFORMAT should be equivalent to the moment.js format string that datetimepicker is
- # using ('YYYY-MM-DD HH:00 ZZ'). The string is used to create a timezone aware datetime object
- DATETIMEFORMAT = '%Y-%m-%d %H:%M %z'
- start_date_time = forms.DateTimeField(input_formats=[DATETIMEFORMAT, ], label='Start')
- end_date_time = forms.DateTimeField(input_formats=[DATETIMEFORMAT, ], label='End')
-
- # we need this to determine if we create a new booking or change an existing booking
- booking_id = forms.IntegerField(widget=forms.HiddenInput, required=False)
-
- def clean(self):
- cleaned_data = super(BookingForm, self).clean()
- if 'start_date_time' not in cleaned_data or 'end_date_time' not in cleaned_data:
- raise forms.ValidationError('Date Missing', code='missing_date')
- if cleaned_data['start_date_time'] >= cleaned_data['end_date_time']:
- raise forms.ValidationError(
- 'Start date is after end date', code='invalid_dates')
- return cleaned_data