diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py index 99db95f7..cb3a0465 100644 --- a/digitalglarus/forms.py +++ b/digitalglarus/forms.py @@ -58,19 +58,54 @@ class BookingBillingForm(BillingAddressForm): class BookingDateForm(forms.Form): - start_date = forms.DateField(required=False, widget=forms.HiddenInput()) - end_date = forms.DateField(required=False, widget=forms.HiddenInput()) - date_range = forms.CharField(required=False, - widget=forms.TextInput(attrs={'id': 'booking-date-range'})) + start_date = forms.DateField(required=False, + widget=forms.TextInput(attrs={'id': 'booking-date-1', + 'value': ''})) + end_date = forms.DateField(required=False, + widget=forms.TextInput(attrs={'id': 'booking-date-2'})) - def clean_date_range(self): - date_range = self.cleaned_data.get('date_range') - dates = date_range.replace(' ', '').split('-') - try: - start_date, end_date = [datetime.strptime(date_string, "%m/%d/%Y").date() - for date_string in dates] - except ValueError: - raise forms.ValidationError("Submit valid dates.") + # def clean_date_range(self): + # date_range = self.cleaned_data.get('date_range') + # dates = date_range.replace(' ', '').split('-') + # try: + # start_date, end_date = [datetime.strptime(date_string, "%m/%d/%Y").date() + # for date_string in dates] + # except ValueError: + # raise forms.ValidationError("Submit valid dates.") + + # if start_date > end_date: + # raise forms.ValidationError("Your end date must be greather than your start date.") + + # q1 = Q(start_date__lte=start_date, end_date__gte=start_date) + # q2 = Q(start_date__gt=start_date, start_date__lte=end_date) + # if Booking.objects.filter(q1 | q2).exists(): + # raise forms.ValidationError("You already have a booking in these dates.") + + # return start_date, end_date + + def clean_start_date(self): + start_date = self.cleaned_data.get('start_date') + if not start_date: + raise forms.ValidationError("This field is required.") + # try: + # start_date = datetime.strptime(start_date, "%m/%d/%Y").date() + # except ValueError: + # raise forms.ValidationError("Submit valid dates.") + return start_date + + def clean_end_date(self): + end_date = self.cleaned_data.get('end_date') + if not end_date: + raise forms.ValidationError("This field is required.") + return end_date + + def clean(self): + + start_date = self.cleaned_data.get('start_date') + end_date = self.cleaned_data.get('end_date') + + if not start_date or not end_date: + return self.cleaned_data if start_date > end_date: raise forms.ValidationError("Your end date must be greather than your start date.") @@ -80,13 +115,4 @@ class BookingDateForm(forms.Form): if Booking.objects.filter(q1 | q2).exists(): raise forms.ValidationError("You already have a booking in these dates.") - return start_date, end_date - - def clean(self): - # import pdb - # pdb.set_trace() - if self.cleaned_data.get('date_range'): - start_date, end_date = self.cleaned_data.get('date_range') - self.cleaned_data['start_date'] = start_date - self.cleaned_data['end_date'] = end_date return self.cleaned_data diff --git a/digitalglarus/static/digitalglarus/js/booking.js b/digitalglarus/static/digitalglarus/js/booking.js index 0cb97667..6ec5e0fd 100644 --- a/digitalglarus/static/digitalglarus/js/booking.js +++ b/digitalglarus/static/digitalglarus/js/booking.js @@ -3,23 +3,44 @@ $( document ).ready(function() { // $('#booking-date-range').daterangepicker(); - var tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); - // var tomorrow = today.setDate(today.getDate() + 1); - $('#booking-date-range').daterangepicker({ - autoUpdateInput: false, - locale: { - cancelLabel: 'Clear' - }, - minDate: tomorrow, - }); - $('#booking-date-range').on('apply.daterangepicker', function(ev, picker) { - $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY')); - }); - $('#booking-date-range').on('cancel.daterangepicker', function(ev, picker) { - $(this).val('Select your dates'); - }); + var tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); + $('#booking-date-1').datetimepicker({ + // minDate: tomorrow, + format: 'MM/d/YYYY', + defaultDate: false + }); + $('#booking-date-2').datetimepicker({ + useCurrent: false, //Important! See issue #1075 + format: 'MM/d/YYYY', + }); + $("#booking-date-1").on("dp.change", function (e) { + $('#booking-date-2').data("DateTimePicker").minDate(e.date); + }); + $("#booking-date-2").on("dp.change", function (e) { + $('#booking-date-1').data("DateTimePicker").maxDate(e.date); + }); + + + // var tomorrow = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); + // // var tomorrow = today.setDate(today.getDate() + 1); + // $('#booking-date-range').daterangepicker({ + // autoUpdateInput: false, + // locale: { + // cancelLabel: 'Clear' + // }, + // minDate: tomorrow, + // }); + + + // $('#booking-date-range').on('apply.daterangepicker', function(ev, picker) { + // $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY')); + // }); + + // $('#booking-date-range').on('dp.cancel', function(ev, picker) { + // $(this).val('Select your dates'); + // }); }); \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/booking.html b/digitalglarus/templates/digitalglarus/booking.html index 2cebebfb..85b15fd2 100644 --- a/digitalglarus/templates/digitalglarus/booking.html +++ b/digitalglarus/templates/digitalglarus/booking.html @@ -14,22 +14,25 @@

Start coworking at Digital Glarus!
Membership costs only 35CHF per month.
2 free working days included!


- {% bootstrap_form_errors form layout='inline' %}
+
+ {% csrf_token %} - {% bootstrap_form_errors form layout='inline' %} + {% bootstrap_form_errors form type='non_fields'%} {% for field in form %} {% bootstrap_field field show_label=False %} {% endfor %} +

+
diff --git a/digitalglarus/templates/digitalglarus/booking_payment.html b/digitalglarus/templates/digitalglarus/booking_payment.html index ff639a92..336ebf70 100644 --- a/digitalglarus/templates/digitalglarus/booking_payment.html +++ b/digitalglarus/templates/digitalglarus/booking_payment.html @@ -45,8 +45,6 @@ {% bootstrap_field field show_label=False type='fields'%} {% endfor %} {% bootstrap_form_errors form type='non_fields'%} - {{form.errors}} -
diff --git a/digitalglarus/templates/new_base_glarus.html b/digitalglarus/templates/new_base_glarus.html index 3819e93b..1085fd0e 100644 --- a/digitalglarus/templates/new_base_glarus.html +++ b/digitalglarus/templates/new_base_glarus.html @@ -25,7 +25,9 @@ + + @@ -227,6 +229,9 @@ --> + +