2021-04-08 16:34:21 +00:00
|
|
|
from django.views.generic import CreateView, UpdateView, ListView
|
2021-03-23 18:23:04 +00:00
|
|
|
from django.urls import reverse_lazy
|
2021-04-08 09:30:19 +00:00
|
|
|
from django.http import HttpResponseRedirect
|
2021-04-08 16:34:21 +00:00
|
|
|
from django.db.models import F
|
2021-04-09 15:01:33 +00:00
|
|
|
from django.shortcuts import get_list_or_404
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-04-11 06:42:14 +00:00
|
|
|
from .models import PartnerProfile, Establishment
|
2021-04-11 06:36:19 +00:00
|
|
|
from .mixins import PartnerProfileRequiredMixin
|
2021-03-22 17:42:07 +00:00
|
|
|
|
2021-04-08 16:34:21 +00:00
|
|
|
from auction.models import Inquiry, Offer
|
2021-04-08 09:30:19 +00:00
|
|
|
from public.mixins import InConstructionMixin
|
2021-03-22 17:42:07 +00:00
|
|
|
from localauth.mixins import LoginRequiredMixin
|
|
|
|
|
2021-04-08 09:30:19 +00:00
|
|
|
class PartnerRegistrationView(InConstructionMixin, LoginRequiredMixin, CreateView):
|
2021-03-22 17:42:07 +00:00
|
|
|
model = PartnerProfile
|
2021-03-23 18:23:04 +00:00
|
|
|
exclude = ["user"]
|
|
|
|
template_name = "partners/signup.html"
|
|
|
|
fields = ["company", "vat_id", "first_name", "last_name", "street", "city", "zip", "state", "country"]
|
|
|
|
|
2021-04-08 09:30:19 +00:00
|
|
|
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)
|
|
|
|
|
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-03-23 18:23:04 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
except:
|
|
|
|
return {}
|
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class PartnerProfileView(InConstructionMixin, PartnerProfileRequiredMixin, UpdateView):
|
2021-03-23 18:23:04 +00:00
|
|
|
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):
|
2021-04-08 16:34:21 +00:00
|
|
|
return self.request.user.partnerprofile
|
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class BiddingListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
2021-04-08 16:34:21 +00:00
|
|
|
model = Inquiry
|
|
|
|
template_name = "partners/bidding_list.html"
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2021-04-09 15:01:33 +00:00
|
|
|
self.establishment = self.get_establishment()
|
|
|
|
|
|
|
|
def get_establishment(self):
|
|
|
|
establishment = self.kwargs.get("id", None)
|
|
|
|
kwargs = {"owner": self.request.user.partnerprofile}
|
|
|
|
|
|
|
|
if establishment:
|
|
|
|
kwargs["id"] = establishment
|
|
|
|
|
|
|
|
return get_list_or_404(Establishment, **kwargs).first()
|
2021-04-08 16:34:21 +00:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return Inquiry.objects.filter(active=True).distance(self.establishment.coords).filter(distance__lte=F("destination_radius"))
|
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class OffersListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
2021-04-08 16:34:21 +00:00
|
|
|
model = Offer
|
|
|
|
template_name = "partners/offer_list.html"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2021-04-09 15:02:45 +00:00
|
|
|
return Offer.objects.filter(establishment__in=self.request.user.partnerprofile.establishment_set.all())
|
2021-04-09 15:01:33 +00:00
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class EstablishmentsListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
2021-04-09 15:01:33 +00:00
|
|
|
model = Establishment
|
|
|
|
template_name = "partners/establishment_list.html"
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2021-04-11 06:36:19 +00:00
|
|
|
return self.request.user.partnerprofile.establishment_set
|
|
|
|
|
2021-04-11 08:11:05 +00:00
|
|
|
class EstablishmentRequestView(InConstructionMixin, PartnerProfileRequiredMixin, ListView):
|
2021-04-11 06:36:19 +00:00
|
|
|
model = Establishment
|
|
|
|
template_name = "partners/establishment_edit.html"
|