Partner views

This commit is contained in:
Kumi 2021-04-08 18:34:21 +02:00
parent dc74a4fc3e
commit f67b10f558
3 changed files with 29 additions and 10 deletions

View file

@ -1,10 +1,12 @@
from django.urls import path from django.urls import path
from .views import PartnerRegistrationView, PartnerProfileView from .views import PartnerRegistrationView, PartnerProfileView, BiddingListView, OffersListView
app_name = "partners" app_name = "partners"
urlpatterns = [ urlpatterns = [
path('register/', PartnerRegistrationView.as_view(), name="register"), path('register/', PartnerRegistrationView.as_view(), name="register"),
path('profile/', PartnerProfileView.as_view(), name="profile"), path('profile/', PartnerProfileView.as_view(), name="profile"),
path('bidding/<int:id>/', BiddingListView.as_view(), name="bidding"),
path('offers/', OffersListView.as_view(), name="offers"),
] ]

View file

@ -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.urls import reverse_lazy
from django.http import HttpResponseRedirect 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 public.mixins import InConstructionMixin
from localauth.mixins import LoginRequiredMixin from localauth.mixins import LoginRequiredMixin
@ -56,4 +58,22 @@ class PartnerProfileView(LoginRequiredMixin, UpdateView):
return reverse_lazy("partners:profile") return reverse_lazy("partners:profile")
def get_object(self, queryset=None): def get_object(self, queryset=None):
return self.request.user.partnerprofile 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())

View file

@ -161,12 +161,9 @@
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a href="#" class="nav-link" data-toggle="dropdown">B2B<span><i class="fa fa-angle-down"></i></span></a> <a href="#" class="nav-link" data-toggle="dropdown">B2B<span><i class="fa fa-angle-down"></i></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
{% if not request.user.partnerprofile %} <li><a class="dropdown-item" href="{% url "partners:profile" %}">{% trans "Mein Profil" %}</a></li>
<li><a class="dropdown-item" href="/">{% trans "Als Anbieter anmelden" %}</a></li> <li><a class="dropdown-item" href="{% url "partners:bidding" %}">{% trans "Bieten" %}</a></li>
{% else %} <li><a class="dropdown-item" href="{% url "partners:offers" %}">{% trans "Angebote verwalten" %}</a></li>
<li><a class="dropdown-item" href="/">{% trans "Bieten" %}</a></li>
<li><a class="dropdown-item" href="/">{% trans "Buchungen verwalten" %}</a></li>
{% endif %}
</ul> </ul>
</li> </li>
{% endif %} {% endif %}