From 6d67541571d5551d28a966c7916de5388d9e397f Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 8 Apr 2021 11:30:19 +0200 Subject: [PATCH] Demo notifications Fixed a few views Other stuff --- auction/helpers.py | 16 ++ auction/models.py | 3 +- auction/urls.py | 4 +- auction/views.py | 35 +++- localauth/mixins.py | 1 + localauth/views.py | 2 +- partners/views.py | 11 +- public/middleware.py | 12 ++ public/mixins.py | 6 + requirements.txt | 4 +- templates/frontend/base.html | 1 + templates/frontend/index.html | 298 ++---------------------------- templates/localauth/authbase.html | 64 +++++++ templates/localauth/login.html | 21 +++ templates/localauth/register.html | 96 ++-------- urlaubsauktion/settings.py | 6 +- 16 files changed, 216 insertions(+), 364 deletions(-) create mode 100644 auction/helpers.py create mode 100644 public/middleware.py create mode 100644 public/mixins.py create mode 100644 templates/localauth/authbase.html create mode 100644 templates/localauth/login.html diff --git a/auction/helpers.py b/auction/helpers.py new file mode 100644 index 0000000..838f57f --- /dev/null +++ b/auction/helpers.py @@ -0,0 +1,16 @@ +from dbsettings.functions import getValue + +import requests + +def name_to_coords(name, api_key=None): + URL = "https://maps.googleapis.com/maps/api/geocode/json" + api_key = api_key or getValue("google.api.key") + + payload = {"address": name, "key": api_key} + response = requests.get(URL, params=payload).json() + + try: + result = response["results"][0] + return result["geometry"]["location"]["lat"], result["geometry"]["location"]["lng"] + except: + raise ValueError(response) \ No newline at end of file diff --git a/auction/models.py b/auction/models.py index ebc4438..efc245c 100644 --- a/auction/models.py +++ b/auction/models.py @@ -4,7 +4,7 @@ from clients.models import ClientProfile from partners.models import Establishment class Inquiry(models.Model): - client = models.ForeignKey(ClientProfile, models.PROTECT) + client = models.ForeignKey(ClientProfile, models.PROTECT, null=True, blank=True) destination_name = models.CharField(max_length=128) destination_coords = models.PointField() destination_radius = models.IntegerField() @@ -14,6 +14,7 @@ class Inquiry(models.Model): adults = models.IntegerField() children = models.IntegerField() comment = models.TextField(null=True, blank=True) + active = models.BooleanField(default=False) @property def is_paid(self): diff --git a/auction/urls.py b/auction/urls.py index 39bdb52..0562a26 100644 --- a/auction/urls.py +++ b/auction/urls.py @@ -2,9 +2,11 @@ from django.urls import path from public.views import HomeView +from .views import InquiryCreateView + app_name = "auction" urlpatterns = [ - path('create_inquiry/', HomeView.as_view(), name="create_inquiry"), + path('create_inquiry/', InquiryCreateView.as_view(), name="create_inquiry"), path('process_inquiry//', HomeView.as_view(), name="process_inquiry"), ] \ No newline at end of file diff --git a/auction/views.py b/auction/views.py index 91ea44a..4002553 100644 --- a/auction/views.py +++ b/auction/views.py @@ -1,3 +1,34 @@ -from django.shortcuts import render +from django.views.generic import CreateView +from django.shortcuts import redirect +from django.contrib import messages +from django.urls import reverse -# Create your views here. +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) \ No newline at end of file diff --git a/localauth/mixins.py b/localauth/mixins.py index a86db25..fa47f4d 100644 --- a/localauth/mixins.py +++ b/localauth/mixins.py @@ -31,4 +31,5 @@ class LoginRequiredMixin: @method_decorator(login_required) def dispatch(self, *args, **kwargs): + messages.info(self.request, "Um diese Seite anzuzeigen, musst du dich einloggen.") return super().dispatch(*args, **kwargs) \ No newline at end of file diff --git a/localauth/views.py b/localauth/views.py index 99d0dd2..9ce5c1f 100644 --- a/localauth/views.py +++ b/localauth/views.py @@ -14,7 +14,7 @@ from clients.models import ClientProfile from partners.models import PartnerProfile class LoginView(Login): - template_name = "localauth/register.html" + template_name = "localauth/login.html" class LogoutView(Logout): next_page = "/" diff --git a/partners/views.py b/partners/views.py index 1509d76..3923545 100644 --- a/partners/views.py +++ b/partners/views.py @@ -1,16 +1,25 @@ from django.views.generic import CreateView, UpdateView from django.urls import reverse_lazy +from django.http import HttpResponseRedirect from .models import PartnerProfile +from public.mixins import InConstructionMixin from localauth.mixins import LoginRequiredMixin -class PartnerRegistrationView(LoginRequiredMixin, CreateView): +class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView): model = PartnerProfile exclude = ["user"] template_name = "partners/signup.html" fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"] + def dispatch(self, request, *args, **kwargs): + try: + PartnerProfile.objects.get(user=request.user) + return HttpResponseRedirect(reverse_lazy("partners:profile")) + except (PartnerProfile.DoesNotExist, TypeError): + return super().dispatch(request, *args, **kwargs) + def form_valid(self, form): form.instance.user = self.request.user return super().form_valid(form) diff --git a/public/middleware.py b/public/middleware.py new file mode 100644 index 0000000..824f36e --- /dev/null +++ b/public/middleware.py @@ -0,0 +1,12 @@ +from django.conf import settings +from django.contrib import messages + +class DemoMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + if settings.DEBUG: + messages.warning(request, "Sie befinden sich auf der Demo-Instanz von JourneyJoker. Diese ist nur zu Testzwecken gedacht und möglicherweise nicht stabil.") + + return self.get_response(request) diff --git a/public/mixins.py b/public/mixins.py new file mode 100644 index 0000000..75dbc59 --- /dev/null +++ b/public/mixins.py @@ -0,0 +1,6 @@ +from django.contrib import messages + +class InConstructionMixin: + def dispatch(self, request, *args, **kwargs): + messages.warning(request, "Die aufgerufene Seite wird aktuell bearbeitet und funktioniert möglicherweise nicht wie erwartet. Versuchen Sie es bitte später wieder oder wenden Sie sich an den Administrator, wenn dieses Problem länger besteht.") + return super().dispatch(request, *args, **kwargs) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 515f851..bab3c2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,6 @@ django-bootstrap4 pyinvoice django-countries paypal-checkout-serversdk -python-dateutil \ No newline at end of file +python-dateutil +qrcode +requests \ No newline at end of file diff --git a/templates/frontend/base.html b/templates/frontend/base.html index e9a79ed..b014a8a 100644 --- a/templates/frontend/base.html +++ b/templates/frontend/base.html @@ -43,6 +43,7 @@ + {{ form.media }} diff --git a/templates/frontend/index.html b/templates/frontend/index.html index f53cbb2..9b9e41c 100644 --- a/templates/frontend/index.html +++ b/templates/frontend/index.html @@ -41,12 +41,8 @@
+ +
@@ -68,7 +64,7 @@
- +
@@ -81,15 +77,28 @@
- +
-
- - +
+ +
@@ -136,273 +145,6 @@
-
-
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
- -
- -
-
-
- -
-
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
- -
- -
-
-
- -
-
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
-
- - -
-
- -
- -
- -
-
-
- -
-
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- -
- -
- -
-
-
-
diff --git a/templates/localauth/authbase.html b/templates/localauth/authbase.html new file mode 100644 index 0000000..9b3baa8 --- /dev/null +++ b/templates/localauth/authbase.html @@ -0,0 +1,64 @@ +{% load static %} + + + + JourneyJoker - {{ title }} + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+
+
+
+ + {% block formspace %} + {% endblock %} + + +
+
+
+
+
+
+ + + + + + + + + + + diff --git a/templates/localauth/login.html b/templates/localauth/login.html new file mode 100644 index 0000000..5572757 --- /dev/null +++ b/templates/localauth/login.html @@ -0,0 +1,21 @@ +{% extends "localauth/authbase.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% block formspace %} + + +
+

{{ title }}

+
+ {% csrf_token %} + {% bootstrap_form form %} + +
+ + +
+{% endblock %} \ No newline at end of file diff --git a/templates/localauth/register.html b/templates/localauth/register.html index 50d164f..161a4f4 100644 --- a/templates/localauth/register.html +++ b/templates/localauth/register.html @@ -1,81 +1,21 @@ -{% load static %} +{% extends "localauth/authbase.html" %} {% load i18n %} {% load bootstrap4 %} - - - - JourneyJoker - {{ title }} - - - - - - - - - - - - - - - - +{% block formspace %} + - - - - - - - - - - -
- - - -
-
-
-
-
-
- - - -
-

{{ title }}

-
- {% csrf_token %} - {% bootstrap_form form %} - -
- - -
- - -
-
-
-
-
-
- - - - - - - - - - - +
+

{{ title }}

+
+ {% csrf_token %} + {% bootstrap_form form %} + +
+ + +
+{% endblock %} \ No newline at end of file diff --git a/urlaubsauktion/settings.py b/urlaubsauktion/settings.py index e46e079..8fe5c5b 100644 --- a/urlaubsauktion/settings.py +++ b/urlaubsauktion/settings.py @@ -33,6 +33,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'public.middleware.DemoMiddleware', ] ROOT_URLCONF = 'urlaubsauktion.urls' @@ -116,4 +117,7 @@ STATICFILES_DIRS = [ AUTH_USER_MODEL = "localauth.User" REGISTER_REDIRECT_URL = "/" -LOGIN_REDIRECT_URL = "/" \ No newline at end of file +LOGIN_REDIRECT_URL = "/" + +LOGIN_URL = "localauth:login" +LOGOUT_URL = "localauth:logout" \ No newline at end of file