From 0b293df0e315bfb92a5393a70b2a67c36a5ff890 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 8 Apr 2020 16:07:43 +0200 Subject: [PATCH] More despair. --- auction/forms.py | 18 +++++++++++++++++- auction/views.py | 29 ++++++++++++++++++----------- requirements.txt | 1 + urlaubsauktion/settings.py | 2 +- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/auction/forms.py b/auction/forms.py index f6564b6..dd68c55 100644 --- a/auction/forms.py +++ b/auction/forms.py @@ -1,8 +1,24 @@ -from django.forms import Form, ModelForm, CharField +from django.forms import ModelForm, DateField, DateInput from profiles.models import ContactProfile +from auction.models import Inquiry class PostPaymentForm(ModelForm): class Meta: model = ContactProfile fields = ["first_name", "last_name", "address", "address2", "zipcode", "city", "country", "phone", "email"] + +class InquiryForm(ModelForm): + class Meta: + model = Inquiry + fields = ["amount", "first_date", "last_date", "destination_name", "adults", "children"] + + first_date = DateField( + widget=DateInput(format='%d.%m.%Y'), + input_formats=('%d.%m.%Y', ) + ) + + last_date = DateField( + widget=DateInput(format='%d.%m.%Y'), + input_formats=('%d.%m.%Y', ) + ) \ No newline at end of file diff --git a/auction/views.py b/auction/views.py index 6d87dc0..2bdbe0a 100644 --- a/auction/views.py +++ b/auction/views.py @@ -9,14 +9,13 @@ from geopy.geocoders import Nominatim from auction.models import Inquiry from profiles.models import ClientProfile, ContactProfile -from auction.forms import PostPaymentForm +from auction.forms import PostPaymentForm, InquiryForm from payment.models import KlarnaPayment, PaypalPayment, StripePayment, DummyPayment # Create your views here. -class InquiryView(CreateView): - model = Inquiry - fields = ["amount", "first_date", "last_date", "destination_name", "adults", "children"] +class InquiryView(FormView): + form_class = InquiryForm def get(self, request, *args, **kwargs): return redirect(reverse_lazy("frontend:index")) @@ -27,20 +26,28 @@ class InquiryView(CreateView): def form_valid(self, form): try: - form.instance.user = ClientProfile.objects.get(user=self.request.user) - except ClientProfile.DoesNotExist: # pylint: disable=no-member - form.instance.user = None + user = ClientProfile.objects.get(user=self.request.user) + except: + user = None - form.instance.currency = "eur" - lat, lon = self.request.POST.get("destination_lat", None), self.request.POST.get("destination_lon", None) if (not lat) or (not lon): location = Nominatim(user_agent="UrlaubsAuktion 1.0").geocode(form.instance.destination_name, country_codes="at") lat, lon = location.latitude, location.longitude - form.instance.destination_geo = Point(lon, lat) - return super().form_valid(form) + inquiry = Inquiry.objects.create( + user = user, + amount = form.cleaned_data["amount"], + first_date = form.cleaned_data["first_date"], + last_date = form.cleaned_data["last_date"], + destination_name = form.cleaned_data["destination_name"], + adults = form.cleaned_data["adults"], + children = form.cleaned_data["children"], + currency = "eur", + destination_geo = Point(lon, lat) + ) + return redirect(inquiry.get_absolute_url()) class PaymentView(DetailView): model = Inquiry diff --git a/requirements.txt b/requirements.txt index 4d6c234..9ed8b94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ django-bootstrap-form django-multiselectfield geopy stripe +Pillow diff --git a/urlaubsauktion/settings.py b/urlaubsauktion/settings.py index 07c2ae6..9583566 100644 --- a/urlaubsauktion/settings.py +++ b/urlaubsauktion/settings.py @@ -145,6 +145,6 @@ MESSAGE_TAGS = { messages.ERROR: 'danger' } -DATE_INPUT_FORMATS = ['%d-%m-%Y','%Y-%m-%d', "%d.%m.%Y"] +DATE_INPUT_FORMATS = ["%d.%m.%Y"] DATETIME_FORMAT = 'd.m.Y' DATE_FORMAT = 'd.m.Y' \ No newline at end of file