From c1e6bfeff248fe92911ab1c2041a614ed9509567 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Sat, 17 Apr 2021 20:35:29 +0200 Subject: [PATCH] Establishment registration, verification and list --- localauth/helpers.py | 2 +- partners/forms.py | 11 +++++++ partners/models.py | 18 ++++++++++-- partners/urls.py | 3 +- partners/views.py | 31 ++++++++++++++++---- templates/auction/process.html | 1 + templates/frontend/base.html | 3 +- templates/partners/establishment_list.html | 10 +++++-- templates/partners/establishment_verify.html | 24 +++++++++++++++ 9 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 partners/forms.py create mode 100644 templates/partners/establishment_verify.html diff --git a/localauth/helpers.py b/localauth/helpers.py index 88bbf10..65c8957 100644 --- a/localauth/helpers.py +++ b/localauth/helpers.py @@ -12,7 +12,7 @@ def name_to_coords(name): return result.latitude, result.longitude def profile_to_coords(profile): - return name_to_coords("%s, %s, %s, %s" % (profile.address, profile.city, profile.zip, profile.country)) + return name_to_coords("%s, %s, %s, %s" % (profile.street, profile.city, profile.zip, profile.country)) def upload_path(instance, filename): return f'userfiles/{instance.user.id}/{uuid.uuid4()}/{filename}' \ No newline at end of file diff --git a/partners/forms.py b/partners/forms.py new file mode 100644 index 0000000..cd6b1ec --- /dev/null +++ b/partners/forms.py @@ -0,0 +1,11 @@ +from django.contrib.auth.forms import UserCreationForm +from django import forms + +from .models import Establishment + +class VerificationForm(forms.Form): + def get_choices(): + for establishment in Establishment.objects.filter(verified=False): + yield ("%i" % establishment.id, "%i – %s" % (establishment.id, establishment.name)) + + establishment = forms.ChoiceField(choices=get_choices) \ No newline at end of file diff --git a/partners/models.py b/partners/models.py index 60e5d3e..ab22c2c 100644 --- a/partners/models.py +++ b/partners/models.py @@ -9,10 +9,22 @@ class PartnerProfile(Profile): class Establishment(LocationMixin, ImageMixin, PhoneMixin): owner = models.ForeignKey(PartnerProfile, models.CASCADE) - name = models.CharField(max_length=64) - stars = models.IntegerField(null=True, blank=True) - superior = models.BooleanField(default=False) + name = models.CharField("Name", max_length=64) + stars = models.IntegerField("Sterne", null=True, blank=True) + superior = models.BooleanField("Superior", default=False) verified = models.BooleanField(default=False) + active = models.BooleanField(default=True) + + @property + def user(self): + return self.owner.user + + @property + def is_active(self): + return self.verified and self.active + + def booking_set(self): + return self.offer_set.filter(accepted=True) class RoomCategory(ImageMixin): establishment = models.ForeignKey(Establishment, models.CASCADE) diff --git a/partners/urls.py b/partners/urls.py index 07ff677..f95e241 100644 --- a/partners/urls.py +++ b/partners/urls.py @@ -1,7 +1,7 @@ from django.urls import path, reverse_lazy from django.views.generic import RedirectView -from .views import PartnerRegistrationView, PartnerProfileView, BiddingListView, OffersListView, EstablishmentsListView, EstablishmentRequestView, PartnerDashboardView +from .views import PartnerRegistrationView, PartnerProfileView, BiddingListView, OffersListView, EstablishmentsListView, EstablishmentRequestView, PartnerDashboardView, EstablishmentVerificationView app_name = "partners" @@ -9,6 +9,7 @@ urlpatterns = [ path('register/', PartnerRegistrationView.as_view(), name="register"), path('profile/', PartnerProfileView.as_view(), name="profile"), path('establishments/', EstablishmentsListView.as_view(), name="establishments"), + path('establishments/validate/', EstablishmentVerificationView.as_view(), name="establishment_verify"), path('establishments/register/', EstablishmentRequestView.as_view(), name="establishment_register"), path('bidding//', BiddingListView.as_view(), name="bidding"), path('bidding/', BiddingListView.as_view(), name="bidding"), diff --git a/partners/views.py b/partners/views.py index 393a3ff..ff0fa77 100644 --- a/partners/views.py +++ b/partners/views.py @@ -1,4 +1,4 @@ -from django.views.generic import CreateView, UpdateView, ListView, DetailView +from django.views.generic import CreateView, UpdateView, ListView, DetailView, FormView from django.urls import reverse_lazy from django.http import HttpResponseRedirect from django.db.models import F @@ -7,10 +7,11 @@ from django.contrib import messages from .models import PartnerProfile, Establishment from .mixins import PartnerProfileRequiredMixin +from .forms import VerificationForm from auction.models import Inquiry, Offer from public.mixins import InConstructionMixin -from localauth.mixins import LoginRequiredMixin +from localauth.mixins import LoginRequiredMixin, SuperUserRequiredMixin class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView): model = PartnerProfile @@ -109,16 +110,36 @@ class EstablishmentsListView(InConstructionMixin, PartnerProfileRequiredMixin, L template_name = "partners/establishment_list.html" def get_queryset(self): - return self.request.user.partnerprofile.establishment_set + return self.request.user.partnerprofile.establishment_set.all() class EstablishmentRequestView(InConstructionMixin, PartnerProfileRequiredMixin, CreateView): model = Establishment template_name = "partners/establishment_register.html" - fields = ["name", "stars", "superior", "street", "city", "zip", "state", "country"] + fields = ["name", "stars", "superior", "street", "city", "zip", "state", "country", "image"] + + def form_valid(self, form): + form.instance.owner = self.request.user.partnerprofile + return super().form_valid(form) + + def get_success_url(self): + return reverse_lazy("partners:establishments") class PartnerDashboardView(InConstructionMixin, PartnerProfileRequiredMixin, DetailView): model = PartnerProfile template_name = "partners/dashboard.html" def get_object(self): - return self.request.user.partnerprofile \ No newline at end of file + return self.request.user.partnerprofile + +class EstablishmentVerificationView(SuperUserRequiredMixin, FormView): + form_class = VerificationForm + template_name = "partners/establishment_verify.html" + + def form_valid(self, form): + eid = form.cleaned_data["establishment"] + eobj = Establishment.objects.get(id=eid) + eobj.update(verified=True) + + messages.success(self.request, "Unterkunft %s bestätigt!" % eobj.name) + + return HttpResponseRedirect(resolve_url("partners:establishment_verify")) \ No newline at end of file diff --git a/templates/auction/process.html b/templates/auction/process.html index b224688..15a8baa 100644 --- a/templates/auction/process.html +++ b/templates/auction/process.html @@ -250,6 +250,7 @@ stripe

{% trans "Die Zahlung per Kreditkarte wird durch unseren Zahlungsdienstleister Stripe abgewickelt." %}

+

{% trans "Der gebotene Betrag wird autorisiert und erst bei verbindlicher Buchung einer Reise tatsächlich von Ihrer Kreditkarte abgebucht." %}

diff --git a/templates/frontend/base.html b/templates/frontend/base.html index dac4c6d..0fdc8b0 100644 --- a/templates/frontend/base.html +++ b/templates/frontend/base.html @@ -192,6 +192,7 @@ @@ -324,7 +325,7 @@ diff --git a/templates/partners/establishment_list.html b/templates/partners/establishment_list.html index b5e6be0..6c5acda 100644 --- a/templates/partners/establishment_list.html +++ b/templates/partners/establishment_list.html @@ -3,6 +3,7 @@ {% block "dashboardcontent" %}

Deine Unterkünfte

+
Neue Unterkunft registrieren
@@ -25,17 +26,20 @@
+ {% for establishment in object_list %} + {% endfor %}
-

Habbo Hotel

+

{{ establishment.name }}

    -
  • Adresse: Stephansplatz 12, Wien, 1010, AT
  • -
  • Buchungen: 1028
  • +
  • Adresse: {{ establishment.full_address }}
  • +
  • Buchungen: {{ establishment.bookings | length }}
  • +
  • Status: {% if establishment.is_active %}aktiv{% else %}inaktiv{% endif %}
Bieten
diff --git a/templates/partners/establishment_verify.html b/templates/partners/establishment_verify.html new file mode 100644 index 0000000..b7aec11 --- /dev/null +++ b/templates/partners/establishment_verify.html @@ -0,0 +1,24 @@ +{% extends "frontend/base.html" %} +{% load i18n %} +{% load bootstrap4 %} +{% block "content" %} + +
+
+
+
+
+
+

{% trans "Unterkunft verifizieren" %}

+ +
+ {% csrf_token %} + {% bootstrap_form form %} + +
+
+
+
+
+
+{% endblock %} \ No newline at end of file