From dc74a4fc3e362189402b4bfb224aa0a7bbcef817 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 8 Apr 2021 13:38:10 +0200 Subject: [PATCH] Getting step two of the inquiry process to display --- auction/models.py | 3 ++ auction/urls.py | 5 ++- auction/views.py | 30 ++++++++++---- public/templatetags/mapimage.py | 24 ++++++++++++ .../auction/{payment.html => process.html} | 39 +++++++++---------- 5 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 public/templatetags/mapimage.py rename templates/auction/{payment.html => process.html} (92%) diff --git a/auction/models.py b/auction/models.py index efc245c..b27df99 100644 --- a/auction/models.py +++ b/auction/models.py @@ -3,7 +3,10 @@ from django.contrib.gis.db import models from clients.models import ClientProfile from partners.models import Establishment +import uuid + class Inquiry(models.Model): + uuid = models.UUIDField(default=uuid.uuid4, unique=True) client = models.ForeignKey(ClientProfile, models.PROTECT, null=True, blank=True) destination_name = models.CharField(max_length=128) destination_coords = models.PointField() diff --git a/auction/urls.py b/auction/urls.py index 0562a26..d556de6 100644 --- a/auction/urls.py +++ b/auction/urls.py @@ -2,11 +2,12 @@ from django.urls import path from public.views import HomeView -from .views import InquiryCreateView +from .views import InquiryCreateView, InquiryUpdateView app_name = "auction" urlpatterns = [ path('create_inquiry/', InquiryCreateView.as_view(), name="create_inquiry"), - path('process_inquiry//', HomeView.as_view(), name="process_inquiry"), + path('process_inquiry//', InquiryUpdateView.as_view(), name="process_inquiry"), + path('create_payment//', HomeView.as_view(), name="inquiry_payment"), ] \ No newline at end of file diff --git a/auction/views.py b/auction/views.py index c475147..e91f9e4 100644 --- a/auction/views.py +++ b/auction/views.py @@ -1,4 +1,4 @@ -from django.views.generic import CreateView +from django.views.generic import CreateView, UpdateView, View from django.shortcuts import redirect from django.contrib import messages from django.urls import reverse @@ -11,11 +11,16 @@ from .helpers import name_to_coords class InquiryCreateView(InConstructionMixin, CreateView): model = Inquiry - fields = ["destination_name", "destination_coords", "budget", "arrival", "min_nights", "adults", "children"] + 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: @@ -24,13 +29,24 @@ class InquiryCreateView(InConstructionMixin, CreateView): return redirect("/") def get_success_url(self): - return reverse("auction:process_inquiry", args=(self.object.id)) + return reverse("auction:process_inquiry", args=(self.object.uuid,)) def clean_destination_coords(self): - lat = self.data.get("destination_lat", "") - lon = self.data.get("destination_lon", "") + 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.cleaned_data.get("destination_name")) + lat, lon = name_to_coords(self.request.POST.get("destination_name")) - return Point(lon, lat) \ No newline at end of file + return Point(lon, lat) + +class InquiryUpdateView(InConstructionMixin, UpdateView): + model = Inquiry + fields = ["destination_radius", "arrival", "min_nights", "budget", "adults", "children", "comment"] + template_name = "auction/process.html" + + def get_object(self): + return Inquiry.objects.get(uuid=self.kwargs["uuid"]) + +class InquiryPaymentView(InConstructionMixin, View): + pass \ No newline at end of file diff --git a/public/templatetags/mapimage.py b/public/templatetags/mapimage.py new file mode 100644 index 0000000..d3d86bb --- /dev/null +++ b/public/templatetags/mapimage.py @@ -0,0 +1,24 @@ +from django import template + +import requests +import base64 + +from dbsettings.models import Setting + +register = template.Library() + +@register.simple_tag +def mapimage(location, zoom=8, width=348, height=250): + payload = { + 'center': f"{location.y},{location.x}", + 'zoom': str(zoom), + "size": "%ix%i" % (width, height), + 'sensor': "false", + 'key': Setting.objects.get(key="google.api.key").value # pylint: disable=no-member + } + + r = requests.get('https://maps.googleapis.com/maps/api/staticmap', params=payload) + image = r.content + data_uri = 'data:image/jpg;base64,' + data_uri += base64.b64encode(image).decode().replace('\n', '') + return data_uri diff --git a/templates/auction/payment.html b/templates/auction/process.html similarity index 92% rename from templates/auction/payment.html rename to templates/auction/process.html index 64e28bd..f3678dd 100644 --- a/templates/auction/payment.html +++ b/templates/auction/process.html @@ -39,25 +39,21 @@
- +
@@ -179,19 +175,12 @@
-
+
- -
-
- - -
-
@@ -246,6 +235,7 @@
@@ -266,6 +256,15 @@
+ +
+ sepa +
+

{% trans "Die Daten für die Überweisung werden im nächsten Schritt angezeigt." %}

+
+ +
+