Add profile view to navigation

Add mixins to views
This commit is contained in:
Kumi 2021-04-11 10:11:05 +02:00
parent 947d77d88d
commit 73c13841c6
3 changed files with 23 additions and 8 deletions

View file

@ -1,11 +1,14 @@
from django.views.generic import CreateView, UpdateView
from django.urls import reverse_lazy
from django.shortcuts import redirect
from django.contrib import messages
from .models import ClientProfile
from localauth.mixins import LoginRequiredMixin
from public.mixins import InConstructionMixin
class ClientRegistrationView(LoginRequiredMixin, CreateView):
class ClientRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView):
model = ClientProfile
exclude = ["user"]
template_name = "clients/signup.html"
@ -16,6 +19,7 @@ class ClientRegistrationView(LoginRequiredMixin, CreateView):
return super().form_valid(form)
def get_success_url(self):
messages.success(self.request, "Profil erfolgreich angelegt!")
return reverse_lazy("clients:profile")
def get_initial(self):
@ -36,11 +40,20 @@ class ClientRegistrationView(LoginRequiredMixin, CreateView):
except:
return {}
class ClientProfileView(LoginRequiredMixin, UpdateView):
class ClientProfileView(InConstructionMixin, LoginRequiredMixin, UpdateView):
model = ClientProfile
exclude = ["user"]
template_name = "clients/profile.html"
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"]
def get_success_url(self):
return reverse_lazy("clients:profile")
return reverse_lazy("clients:profile")
def get_object(self, queryset=None):
return self.request.user.clientprofile
def get(self, request, *args, **kwargs):
try:
return super().get(request, *args, **kwargs)
except ClientProfile.DoesNotExist:
return redirect("clients:register")

View file

@ -29,6 +29,7 @@ class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateVie
return super().form_valid(form)
def get_success_url(self):
messages.success(self.request, "Profil erfolgreich angelegt!")
return reverse_lazy("partners:profile")
def get_initial(self):
@ -50,7 +51,7 @@ class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateVie
except:
return {}
class PartnerProfileView(PartnerProfileRequiredMixin, UpdateView):
class PartnerProfileView(InConstructionMixin, PartnerProfileRequiredMixin, UpdateView):
model = PartnerProfile
exclude = ["user"]
template_name = "partners/profile.html"
@ -62,7 +63,7 @@ class PartnerProfileView(PartnerProfileRequiredMixin, UpdateView):
def get_object(self, queryset=None):
return self.request.user.partnerprofile
class BiddingListView(PartnerProfileRequiredMixin, ListView):
class BiddingListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
model = Inquiry
template_name = "partners/bidding_list.html"
@ -82,20 +83,20 @@ class BiddingListView(PartnerProfileRequiredMixin, ListView):
def get_queryset(self):
return Inquiry.objects.filter(active=True).distance(self.establishment.coords).filter(distance__lte=F("destination_radius"))
class OffersListView(PartnerProfileRequiredMixin, ListView):
class OffersListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
model = Offer
template_name = "partners/offer_list.html"
def get_queryset(self):
return Offer.objects.filter(establishment__in=self.request.user.partnerprofile.establishment_set.all())
class EstablishmentsListView(PartnerProfileRequiredMixin, ListView):
class EstablishmentsListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
model = Establishment
template_name = "partners/establishment_list.html"
def get_queryset(self):
return self.request.user.partnerprofile.establishment_set
class EstablishmentRequestView(PartnerProfileRequiredMixin, ListView):
class EstablishmentRequestView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
model = Establishment
template_name = "partners/establishment_edit.html"

View file

@ -149,6 +149,7 @@
<a href="#" class="nav-link" data-toggle="dropdown">{% trans "Mein&nbsp;Urlaub" %}<span><i class="fa fa-angle-down"></i></span></a>
<ul class="dropdown-menu">
{% if request.user.is_authenticated %}
<li><a class="dropdown-item" href="{% url "clients:profile" %}">{% trans "Mein Profil" %}</a></li>
<li><a class="dropdown-item" href="/">{% trans "Gestellte Anfragen" %}</a></li>
<li><a class="dropdown-item" href="/">{% trans "Gebuchte Reisen" %}</a></li>
{% else %}