diff --git a/lemarche/templates/tenders/_list_item_siae.html b/lemarche/templates/tenders/_list_item_siae.html index fe5bfbeaa..725bcdf63 100644 --- a/lemarche/templates/tenders/_list_item_siae.html +++ b/lemarche/templates/tenders/_list_item_siae.html @@ -16,7 +16,7 @@ {% endif %} Disponible jusqu'au : {{ tender.deadline_date|default:"" }} - {% if not tender.tendersiae_set.first.detail_display_date %} + {% if not current_siae.detail_display_date %} Nouveau {% endif %} {% endif %} diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 555c72ed6..914e2c9c7 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -2,7 +2,6 @@ from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.core.paginator import Paginator -from django.db.models import Prefetch from django.http import HttpResponseForbidden, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy @@ -277,6 +276,7 @@ class TenderListView(LoginRequiredMixin, ListView): paginate_by = 10 paginator_class = Paginator status = None + siae: Siae = None def get_queryset(self): """ @@ -288,11 +288,9 @@ def get_queryset(self): if user.kind == User.KIND_SIAE and user.siaes: siaes = user.siaes.all() if siaes: - # filtered prefetch to get detail_display_date on tendersiae_set related to user's siaes - tendersiae_qs = TenderSiae.objects.filter(siae__in=siaes) - qs = Tender.objects.filter_with_siaes(siaes).prefetch_related( - Prefetch("tendersiae_set", queryset=tendersiae_qs) - ) + # we get the first siae by default + self.siae = siaes[0] + qs = Tender.objects.filter_with_siaes(siaes) else: qs = Tender.objects.by_user(user).with_siae_stats() if self.status: @@ -326,6 +324,8 @@ def get_context_data(self, **kwargs): context["title_kind_sourcing_siae"] = TITLE_KIND_SOURCING_SIAE context["tender_constants"] = tender_constants context["filter_form"] = self.filter_form + if self.siae: + context["current_siae"] = self.siae return context