More despair.

This commit is contained in:
Kumi 2020-04-08 16:07:43 +02:00
parent 7252b0c52c
commit 0b293df0e3
4 changed files with 37 additions and 13 deletions

View file

@ -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', )
)

View file

@ -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

View file

@ -10,3 +10,4 @@ django-bootstrap-form
django-multiselectfield
geopy
stripe
Pillow

View file

@ -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'