JourneyJoker/auction/views.py
Klaus-Uwe Mitterer 6d67541571 Demo notifications
Fixed a few views
Other stuff
2021-04-08 11:30:19 +02:00

34 lines
No EOL
1.1 KiB
Python

from django.views.generic import CreateView
from django.shortcuts import redirect
from django.contrib import messages
from django.urls import reverse
from public.mixins import InConstructionMixin
from .models import Inquiry
class InquiryCreateView(InConstructionMixin, CreateView):
model = Inquiry
fields = ["destination_name", "destination_coords", "budget", "arrival", "min_nights", "adults", "children"]
def get(self, request, *args, **kwargs):
return redirect("/")
def form_invalid(self, form, *args, **kwargs):
for field in form:
for error in field.errors:
messages.error(self.request, f"{field.name}: {error}")
return redirect("/")
def get_success_url(self):
return reverse("auction:process_inquiry", args=(self.object.id))
def clean_destination_coords(self):
lat = self.cleaned_data.get("destination_lat", "")
lon = self.cleaned_data.get("destination_lon", "")
if (not lat) or (not lon):
lon, lat = get_coords(self.cleaned_data.get("destination_name"))
return Point(lon, lat)