From ae9b760cb88ad8eef948f39c09506edba58ff0b0 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Mon, 12 Apr 2021 14:39:18 +0200 Subject: [PATCH] Prettifying a few client views --- clients/urls.py | 3 +- clients/views.py | 7 ++- localauth/helpers.py | 7 ++- localauth/models.py | 14 ++++- partners/models.py | 9 +-- templates/clients/base.html | 37 +++++++++++ templates/clients/dashboard.html | 102 +++++++++++++++++++++++++++++++ templates/clients/profile.html | 45 +++++++++----- templates/frontend/base.html | 3 + 9 files changed, 201 insertions(+), 26 deletions(-) create mode 100644 templates/clients/base.html create mode 100644 templates/clients/dashboard.html diff --git a/clients/urls.py b/clients/urls.py index 4ed5ae4..8dc9ac0 100644 --- a/clients/urls.py +++ b/clients/urls.py @@ -1,10 +1,11 @@ from django.urls import path -from .views import ClientRegistrationView, ClientProfileView +from .views import ClientRegistrationView, ClientProfileView, ClientDashboardView app_name = "clients" urlpatterns = [ + path('dashboard/', ClientDashboardView.as_view(), name="dashboard"), path('register/', ClientRegistrationView.as_view(), name="register"), path('profile/', ClientProfileView.as_view(), name="profile"), ] \ No newline at end of file diff --git a/clients/views.py b/clients/views.py index e5ccdef..688db5c 100644 --- a/clients/views.py +++ b/clients/views.py @@ -1,4 +1,4 @@ -from django.views.generic import CreateView, UpdateView +from django.views.generic import CreateView, UpdateView, TemplateView from django.urls import reverse_lazy from django.shortcuts import redirect from django.contrib import messages @@ -56,4 +56,7 @@ class ClientProfileView(InConstructionMixin, LoginRequiredMixin, UpdateView): try: return super().get(request, *args, **kwargs) except ClientProfile.DoesNotExist: - return redirect("clients:register") \ No newline at end of file + return redirect("clients:register") + +class ClientDashboardView(InConstructionMixin, LoginRequiredMixin, TemplateView): + template_name = "clients/dashboard.html" \ No newline at end of file diff --git a/localauth/helpers.py b/localauth/helpers.py index 35e2d07..88bbf10 100644 --- a/localauth/helpers.py +++ b/localauth/helpers.py @@ -2,6 +2,8 @@ from django.conf import settings from geopy.geocoders import Nominatim +import uuid + def name_to_coords(name): geocoder = Nominatim(user_agent="JourneyJoker.at") @@ -10,4 +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)) \ No newline at end of file + return name_to_coords("%s, %s, %s, %s" % (profile.address, 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/localauth/models.py b/localauth/models.py index 5163bf9..7e3e3da 100644 --- a/localauth/models.py +++ b/localauth/models.py @@ -6,7 +6,7 @@ from django.utils import timezone from django_countries.fields import CountryField -from .helpers import profile_to_coords +from .helpers import profile_to_coords, upload_path class UserManager(BaseUserManager): use_in_migrations = True @@ -70,6 +70,10 @@ class AddressMixin(models.Model): state = models.CharField(max_length=64, null=True, blank=True) country = CountryField() + @property + def full_address(self): + return f"{self.street}, {self.city}, {self.zip}, {self.state}, {self.country}" + class Meta: abstract = True @@ -85,7 +89,13 @@ class LocationMixin(AddressMixin): class Meta: abstract = True -class Profile(AddressMixin, models.Model): +class ImageMixin(models.Model): + image = models.ImageField(upload_to=upload_path) + + class Meta: + abstract = True + +class Profile(AddressMixin): user = models.OneToOneField(User, models.CASCADE) company = models.CharField(max_length=64, null=True, blank=True) vat_id = models.CharField(max_length=32, null=True, blank=True) diff --git a/partners/models.py b/partners/models.py index 4708793..85156c9 100644 --- a/partners/models.py +++ b/partners/models.py @@ -1,19 +1,20 @@ from django.contrib.gis.db import models -from localauth.models import User, Profile, LocationMixin +from localauth.models import User, Profile, LocationMixin, ImageMixin from django_countries.fields import CountryField class PartnerProfile(Profile): pass -class Establishment(LocationMixin, models.Model): +class Establishment(LocationMixin, ImageMixin): owner = models.ForeignKey(PartnerProfile, models.CASCADE) name = models.CharField(max_length=64) stars = models.IntegerField(null=True, blank=True) superior = models.BooleanField(default=False) verified = models.BooleanField(default=False) -class RoomCategory(models.Model): +class RoomCategory(ImageMixin): establishment = models.ForeignKey(Establishment, models.CASCADE) - name = models.CharField(max_length=64) \ No newline at end of file + name = models.CharField(max_length=64) + price = models.DecimalField(max_digits=10, decimal_places=2) \ No newline at end of file diff --git a/templates/clients/base.html b/templates/clients/base.html new file mode 100644 index 0000000..129eb8c --- /dev/null +++ b/templates/clients/base.html @@ -0,0 +1,37 @@ +{% extends "frontend/base.html" %} +{% block "content" %} + +
+
+
+
+
+
+

Dein Profil

+

Servus {{ request.user.get_full_name }}, willkommen in deinem JourneyJoker-Profil!

+

Hier siehst du all deine gebuchten Reisen und kannst deine Daten verwalten!

+
+ +
+
+ + + + {% block "dashboardcontent" %} + {% endblock %} + +
+
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/clients/dashboard.html b/templates/clients/dashboard.html new file mode 100644 index 0000000..f88e17d --- /dev/null +++ b/templates/clients/dashboard.html @@ -0,0 +1,102 @@ +{% extends "clients/base.html" %} +{% block "dashboardcontent" %} +
+

Deine Statistik

+
+ +
+
+ +

4

+

Bewertungen

+
+
+ +
+
+ +

12345

+

Euro

+
+
+ +
+
+ +

12

+

Städte

+
+
+ +
+
+ +

102

+

Reisen

+
+
+ +
+ +
+

Letzte Aktivitäten

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Deine Bewertung für Habbo Hotel wurde freigeschaltet!
Wie war dein Aufenthalt bei Habbo Hotel? Gib eine Bewertung ab!
Deine Buchung war erfolgreich! Mehr Details zu deinem Aufenthalt bei Habbo Hotel!
Du hast Angebote zu deiner Reiseanfrage erhalten! Jetzt ansehen?
Deine Reiseanfrage wurde freigeschaltet! Bald wirst du erste Angebote erhalten!
+
+
+ +
+

Rechnungen

+
+ + + + + + + + +
+

Reiseanfrage

+
    +
  • Bezahlt
  • +
  • Anfrage: #00214
  • +
  • Erstellt: 25.03.2021
  • +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/clients/profile.html b/templates/clients/profile.html index 6e6d88a..0065a8b 100644 --- a/templates/clients/profile.html +++ b/templates/clients/profile.html @@ -1,21 +1,34 @@ -{% extends "frontend/base.html" %} +{% extends "clients/base.html" %} {% load i18n %} {% load bootstrap4 %} -{% block "content" %} - -
-
-
-
-
-

{% trans "Profildaten" %}

-
- {% csrf_token %} - {% bootstrap_form form %} - +{% block "dashboardcontent" %} +
+ + + + {% endblock %} \ No newline at end of file diff --git a/templates/frontend/base.html b/templates/frontend/base.html index 05d86bc..8b01d08 100644 --- a/templates/frontend/base.html +++ b/templates/frontend/base.html @@ -327,6 +327,9 @@ + {% block "modal" %} + {% endblock %} +