From a44e4f4733d0113fc3b494c1c1338517d3e487a5 Mon Sep 17 00:00:00 2001 From: Levi Date: Fri, 14 Oct 2016 01:04:40 -0500 Subject: [PATCH 1/2] Fixed Error on Allowed booking days by user --- digitalglarus/forms.py | 11 ++++++++--- digitalglarus/views.py | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py index 6982037f..f5bb53aa 100644 --- a/digitalglarus/forms.py +++ b/digitalglarus/forms.py @@ -81,6 +81,10 @@ class BookingDateForm(forms.Form): end_date = forms.DateField(required=False, widget=forms.TextInput(attrs={'id': 'booking-date-2'})) + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super(BookingDateForm, self).__init__(*args, **kwargs) + def clean_start_date(self): start_date = self.cleaned_data.get('start_date') if not start_date: @@ -94,7 +98,6 @@ class BookingDateForm(forms.Form): return end_date def clean(self): - start_date = self.cleaned_data.get('start_date') end_date = self.cleaned_data.get('end_date') @@ -104,8 +107,10 @@ class BookingDateForm(forms.Form): 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) + q1 = Q(bookingorder__customer__user=self.user, + start_date__lte=start_date, end_date__gte=start_date) + q2 = Q(bookingorder__customer__user=self.user, + 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.") diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 0fa81637..2b11e65a 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -96,6 +96,11 @@ class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormVi login_url = reverse_lazy('digitalglarus:login') success_url = reverse_lazy('digitalglarus:booking_payment') + def get_form_kwargs(self): + kwargs = super(BookingSelectDatesView, self).get_form_kwargs() + kwargs.update({'user': self.request.user}) + return kwargs + def form_valid(self, form): user = self.request.user start_date = form.cleaned_data.get('start_date') From 86583993cdda46ad7a5df7389b38757e945a703e Mon Sep 17 00:00:00 2001 From: Levi Date: Fri, 14 Oct 2016 01:06:09 -0500 Subject: [PATCH 2/2] #hotfix removed import pdb --- digitalglarus/management/commands/make_membership_charge.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/digitalglarus/management/commands/make_membership_charge.py b/digitalglarus/management/commands/make_membership_charge.py index 4dedc1ff..41013b12 100644 --- a/digitalglarus/management/commands/make_membership_charge.py +++ b/digitalglarus/management/commands/make_membership_charge.py @@ -67,8 +67,6 @@ class Command(BaseCommand): 'amount': current_membership_price } membership_order_form = MembershipOrderForm(membership_order_data) - import pdb - pdb.set_trace() if membership_order_form.is_valid(): membership_order = membership_order_form.save()