115 lines
No EOL
4.3 KiB
Python
115 lines
No EOL
4.3 KiB
Python
from django.views.generic import CreateView, UpdateView, ListView, DetailView, FormView
|
|
from django.urls import reverse_lazy
|
|
from django.http import HttpResponseRedirect
|
|
from django.shortcuts import get_list_or_404, redirect, get_object_or_404
|
|
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, SuperUserRequiredMixin
|
|
|
|
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", "phone"]
|
|
|
|
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)
|
|
|
|
def get_success_url(self):
|
|
messages.success(self.request, "Profil erfolgreich angelegt!")
|
|
return reverse_lazy("partners:profile")
|
|
|
|
def get_initial(self):
|
|
try:
|
|
client = self.request.user.clientprofile
|
|
|
|
return {
|
|
"company": client.company,
|
|
"vat_id": client.vat_id,
|
|
"first_name": client.first_name,
|
|
"last_name": client.last_name,
|
|
"street": client.street,
|
|
"city": client.city,
|
|
"zip": client.zip,
|
|
"state": client.state,
|
|
"country": client.country,
|
|
"phone": client.phone
|
|
}
|
|
|
|
except:
|
|
return {
|
|
"country": "AT",
|
|
"phone": "+43"
|
|
}
|
|
|
|
class PartnerProfileView(InConstructionMixin, PartnerProfileRequiredMixin, UpdateView):
|
|
model = PartnerProfile
|
|
exclude = ["user"]
|
|
template_name = "partners/profile.html"
|
|
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"]
|
|
|
|
def get_success_url(self):
|
|
return reverse_lazy("partners:profile")
|
|
|
|
def get_object(self, queryset=None):
|
|
return self.request.user.partnerprofile
|
|
|
|
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(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
|
model = Establishment
|
|
template_name = "partners/establishment_list.html"
|
|
|
|
def get_queryset(self):
|
|
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", "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
|
|
|
|
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.filter(id=eid)
|
|
eobj.update(verified=True)
|
|
|
|
messages.success(self.request, "Unterkunft %s bestätigt!" % eobj[0].name)
|
|
|
|
return HttpResponseRedirect(resolve_url("partners:establishment_verify")) |