diff options
author | maxbr <maxbr@mi.fu-berlin.de> | 2016-07-29 12:43:43 +0200 |
---|---|---|
committer | Max Breitenfeldt <max.breitenfeldt@gmail.com> | 2016-07-29 11:25:20 +0000 |
commit | 35c34c690ae9616d791c39fa218fe1621fa8d8d2 (patch) | |
tree | 6168caaeb4be9144ed6bfde0150850d6559c8b6f /tools/pharos-dashboard/dashboard/forms | |
parent | 7ae1f204de947a3c12804c04f32e20d45eb99eba (diff) |
import pharos dashboard code
JIRA: RELENG-12
The last commit was missing some JS/CSS dependencies of the site. This
happened because they are in folders that are named 'build' or 'dist'.
This commit adds a bower.json file, that specifies dependencies.
Dependencies can now be installed by running 'bower install' in the
dashboard/static folder.
Change-Id: I054f319c66771f767e97711cb678d79d3bd6bee4
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'tools/pharos-dashboard/dashboard/forms')
-rw-r--r-- | tools/pharos-dashboard/dashboard/forms/booking_form.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/pharos-dashboard/dashboard/forms/booking_form.py b/tools/pharos-dashboard/dashboard/forms/booking_form.py new file mode 100644 index 00000000..9cf8048f --- /dev/null +++ b/tools/pharos-dashboard/dashboard/forms/booking_form.py @@ -0,0 +1,37 @@ +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 |