2021-04-15 08:34:31 +00:00
|
|
|
from django.views.generic import CreateView, UpdateView, View, ListView, DetailView
|
|
|
|
from django.shortcuts import redirect, get_object_or_404
|
2021-04-08 09:30:19 +00:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.urls import reverse
|
2021-04-08 09:33:00 +00:00
|
|
|
from django.contrib.gis.geos import Point
|
2021-03-01 09:58:08 +00:00
|
|
|
|
2021-04-08 09:30:19 +00:00
|
|
|
from public.mixins import InConstructionMixin
|
2021-04-12 07:49:00 +00:00
|
|
|
from localauth.helpers import name_to_coords
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-15 08:34:31 +00:00
|
|
|
from .models import Inquiry, Offer
|
2021-04-13 12:44:22 +00:00
|
|
|
from .forms import InquiryProcessForm
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-13 12:44:22 +00:00
|
|
|
class InquiryCreateView(CreateView):
|
2021-04-08 09:30:19 +00:00
|
|
|
model = Inquiry
|
2021-04-08 11:38:10 +00:00
|
|
|
fields = ["destination_name", "budget", "arrival", "min_nights", "adults", "children"]
|
2021-04-08 09:30:19 +00:00
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
return redirect("/")
|
|
|
|
|
2021-04-08 11:38:10 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.destination_coords = self.clean_destination_coords()
|
|
|
|
form.instance.destination_radius = 0
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
2021-04-08 09:30:19 +00:00
|
|
|
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):
|
2021-04-08 11:38:10 +00:00
|
|
|
return reverse("auction:process_inquiry", args=(self.object.uuid,))
|
2021-04-08 09:30:19 +00:00
|
|
|
|
|
|
|
def clean_destination_coords(self):
|
2021-04-17 06:36:26 +00:00
|
|
|
lat, lon = name_to_coords(self.request.POST.get("destination_name"))
|
2021-04-08 11:38:10 +00:00
|
|
|
return Point(lon, lat)
|
|
|
|
|
2021-04-13 12:44:22 +00:00
|
|
|
class InquiryProcessView(InConstructionMixin, UpdateView):
|
|
|
|
form_class = InquiryProcessForm
|
2021-04-08 11:38:10 +00:00
|
|
|
model = Inquiry
|
|
|
|
template_name = "auction/process.html"
|
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
return Inquiry.objects.get(uuid=self.kwargs["uuid"])
|
2021-04-08 09:30:19 +00:00
|
|
|
|
2021-04-13 12:44:22 +00:00
|
|
|
def get_initial(self):
|
|
|
|
initial = super().get_initial()
|
|
|
|
|
|
|
|
try:
|
|
|
|
initial["country"] = self.request.user.clientprofile.country.code
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return initial
|
|
|
|
|
2021-04-08 11:38:10 +00:00
|
|
|
class InquiryPaymentView(InConstructionMixin, View):
|
2021-04-15 08:34:31 +00:00
|
|
|
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"])
|
|
|
|
|