From f67b10f558150a6353898c2babac373801332d2b Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 8 Apr 2021 18:34:21 +0200 Subject: [PATCH] Partner views --- partners/urls.py | 4 +++- partners/views.py | 26 +++++++++++++++++++++++--- templates/frontend/base.html | 9 +++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/partners/urls.py b/partners/urls.py index 4ed0051..ea4e64a 100644 --- a/partners/urls.py +++ b/partners/urls.py @@ -1,10 +1,12 @@ from django.urls import path -from .views import PartnerRegistrationView, PartnerProfileView +from .views import PartnerRegistrationView, PartnerProfileView, BiddingListView, OffersListView app_name = "partners" urlpatterns = [ path('register/', PartnerRegistrationView.as_view(), name="register"), path('profile/', PartnerProfileView.as_view(), name="profile"), + path('bidding//', BiddingListView.as_view(), name="bidding"), + path('offers/', OffersListView.as_view(), name="offers"), ] \ No newline at end of file diff --git a/partners/views.py b/partners/views.py index 3923545..c5dc2f8 100644 --- a/partners/views.py +++ b/partners/views.py @@ -1,9 +1,11 @@ -from django.views.generic import CreateView, UpdateView +from django.views.generic import CreateView, UpdateView, ListView from django.urls import reverse_lazy from django.http import HttpResponseRedirect +from django.db.models import F -from .models import PartnerProfile +from .models import PartnerProfile, Establishment +from auction.models import Inquiry, Offer from public.mixins import InConstructionMixin from localauth.mixins import LoginRequiredMixin @@ -56,4 +58,22 @@ class PartnerProfileView(LoginRequiredMixin, UpdateView): return reverse_lazy("partners:profile") def get_object(self, queryset=None): - return self.request.user.partnerprofile \ No newline at end of file + return self.request.user.partnerprofile + +class BiddingListView(LoginRequiredMixin, ListView): + model = Inquiry + template_name = "partners/bidding_list.html" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.establishment = Establishment.objects.get(id=self.kwargs["id"], owner=self.request.user.partnerprofile) + + def get_queryset(self): + return Inquiry.objects.filter(active=True).distance(self.establishment.coords).filter(distance__lte=F("destination_radius")) + +class OffersListView(LoginRequiredMixin, 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()) \ No newline at end of file diff --git a/templates/frontend/base.html b/templates/frontend/base.html index b014a8a..80b3d48 100644 --- a/templates/frontend/base.html +++ b/templates/frontend/base.html @@ -161,12 +161,9 @@ {% endif %}