2021-04-20 08:00:24 +00:00
|
|
|
from django.views.generic import CreateView, UpdateView, TemplateView, ListView, DetailView
|
2021-03-23 18:23:04 +00:00
|
|
|
from django.urls import reverse_lazy
|
2021-04-11 08:11:05 +00:00
|
|
|
from django.shortcuts import redirect
|
|
|
|
from django.contrib import messages
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-03-23 18:23:04 +00:00
|
|
|
from .models import ClientProfile
|
2021-05-26 16:42:22 +00:00
|
|
|
from .mixins import ClientBaseMixin
|
2021-03-23 18:23:04 +00:00
|
|
|
|
2021-05-26 16:42:22 +00:00
|
|
|
from localauth.mixins import LoginRequiredMixin, RedirectToNextMixin
|
2021-05-30 14:10:08 +00:00
|
|
|
from frontend.mixins import InConstructionMixin
|
2021-04-12 13:32:15 +00:00
|
|
|
from auction.models import Inquiry
|
2021-03-23 18:23:04 +00:00
|
|
|
|
2021-05-26 16:42:22 +00:00
|
|
|
class ClientRegistrationView(LoginRequiredMixin, RedirectToNextMixin, CreateView):
|
2021-03-23 18:23:04 +00:00
|
|
|
model = ClientProfile
|
|
|
|
exclude = ["user"]
|
|
|
|
template_name = "clients/signup.html"
|
2021-04-14 11:15:36 +00:00
|
|
|
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country", "phone"]
|
2021-03-23 18:23:04 +00:00
|
|
|
|
2021-04-13 12:44:22 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
try:
|
|
|
|
ClientProfile.objects.get(user=request.user)
|
2021-05-27 03:37:58 +00:00
|
|
|
return redirect(reverse_lazy("clients:profile"))
|
2021-04-13 12:44:22 +00:00
|
|
|
except (ClientProfile.DoesNotExist, TypeError):
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
|
2021-03-23 18:23:04 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.user = self.request.user
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_success_url(self):
|
2021-04-11 08:11:05 +00:00
|
|
|
messages.success(self.request, "Profil erfolgreich angelegt!")
|
2021-05-26 16:42:22 +00:00
|
|
|
return redirect(self.get_redirect_url()) if self.get_redirect_url() else reverse_lazy("clients:profile")
|
2021-03-23 18:23:04 +00:00
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
try:
|
|
|
|
partner = self.request.user.partnerprofile
|
|
|
|
return {
|
|
|
|
"company": partner.company,
|
|
|
|
"vat_id": partner.vat_id,
|
|
|
|
"first_name": partner.first_name,
|
|
|
|
"last_name": partner.last_name,
|
|
|
|
"street": partner.street,
|
|
|
|
"city": partner.city,
|
|
|
|
"zip": partner.zip,
|
|
|
|
"state": partner.state,
|
2021-04-14 11:15:36 +00:00
|
|
|
"country": partner.country,
|
|
|
|
"phone": partner.phone,
|
2021-03-23 18:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
except:
|
2021-04-14 11:15:36 +00:00
|
|
|
return {
|
|
|
|
"country": "AT",
|
|
|
|
"phone": "+43"
|
|
|
|
}
|
2021-03-23 18:23:04 +00:00
|
|
|
|
2021-05-26 12:08:15 +00:00
|
|
|
class ClientProfileView(ClientBaseMixin, UpdateView):
|
2021-03-23 18:23:04 +00:00
|
|
|
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):
|
2021-04-11 08:11:05 +00:00
|
|
|
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:
|
2021-04-12 12:39:18 +00:00
|
|
|
return redirect("clients:register")
|
|
|
|
|
2021-05-26 12:08:15 +00:00
|
|
|
class ClientDashboardView(ClientBaseMixin, DetailView):
|
2021-04-20 08:00:24 +00:00
|
|
|
model = ClientProfile
|
2021-04-12 13:32:15 +00:00
|
|
|
template_name = "clients/dashboard.html"
|
|
|
|
|
2021-04-20 08:00:24 +00:00
|
|
|
def get_object(self):
|
|
|
|
return self.request.user.clientprofile
|
|
|
|
|
2021-05-26 12:08:15 +00:00
|
|
|
class ClientBookingsView(ClientBaseMixin, ListView):
|
2021-04-12 13:32:15 +00:00
|
|
|
model = Inquiry
|
|
|
|
template_name = "clients/bookings.html"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2021-04-20 11:37:36 +00:00
|
|
|
return Inquiry.objects.filter(client=self.request.user.clientprofile)
|