79 lines
No EOL
2.4 KiB
Python
79 lines
No EOL
2.4 KiB
Python
from django.views.generic import CreateView, UpdateView, View, ListView, DetailView
|
|
from django.shortcuts import redirect, get_object_or_404
|
|
from django.contrib import messages
|
|
from django.urls import reverse
|
|
from django.contrib.gis.geos import Point
|
|
|
|
from public.mixins import InConstructionMixin
|
|
from localauth.helpers import name_to_coords
|
|
|
|
from .models import Inquiry, Offer
|
|
from .forms import InquiryProcessForm
|
|
|
|
class InquiryCreateView(CreateView):
|
|
model = Inquiry
|
|
fields = ["destination_name", "budget", "arrival", "min_nights", "adults", "children"]
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
return redirect("/")
|
|
|
|
def form_valid(self, form):
|
|
form.instance.destination_coords = self.clean_destination_coords()
|
|
form.instance.destination_radius = 0
|
|
return super().form_valid(form)
|
|
|
|
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.uuid,))
|
|
|
|
def clean_destination_coords(self):
|
|
lat = self.request.POST.get("destination_lat", "")
|
|
lon = self.request.POST.get("destination_lon", "")
|
|
|
|
if (not lat) or (not lon):
|
|
lat, lon = name_to_coords(self.request.POST.get("destination_name"))
|
|
|
|
return Point(lon, lat)
|
|
|
|
class InquiryProcessView(InConstructionMixin, UpdateView):
|
|
form_class = InquiryProcessForm
|
|
model = Inquiry
|
|
template_name = "auction/process.html"
|
|
|
|
def get_object(self):
|
|
return Inquiry.objects.get(uuid=self.kwargs["uuid"])
|
|
|
|
def get_initial(self):
|
|
initial = super().get_initial()
|
|
|
|
try:
|
|
initial["country"] = self.request.user.clientprofile.country.code
|
|
except:
|
|
pass
|
|
|
|
return initial
|
|
|
|
class InquiryPaymentView(InConstructionMixin, View):
|
|
pass
|
|
|
|
class OfferSelectionView(InConstructionMixin, DetailView):
|
|
model = Inquiry
|
|
template_name = "auction/offer_select.html"
|
|
|
|
def get_object(self):
|
|
return get_object_or_404(Inquiry, uuid=self.kwargs["uuid"])
|
|
|
|
class OfferSelectionTableView(ListView):
|
|
model = Offer
|
|
content_type = "text/javascript"
|
|
template_name = "auction/offer_table.js"
|
|
|
|
def get_queryset(self):
|
|
inquiry = get_object_or_404(Inquiry, uuid=self.kwargs["uuid"])
|
|
|