From f7cd20e61731ae01b51d3fccaf520c4de0e0b9d9 Mon Sep 17 00:00:00 2001 From: "madjid.asa" Date: Thu, 14 Mar 2024 11:59:21 +0100 Subject: [PATCH] fix details --- lemarche/templates/tenders/_detail_card.html | 2 +- lemarche/templates/tenders/detail.html | 2 +- lemarche/www/tenders/tests.py | 31 ++++++++++++++++++++ lemarche/www/tenders/views.py | 5 ++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lemarche/templates/tenders/_detail_card.html b/lemarche/templates/tenders/_detail_card.html index 265e05876..86fa4dc07 100644 --- a/lemarche/templates/tenders/_detail_card.html +++ b/lemarche/templates/tenders/_detail_card.html @@ -2,7 +2,7 @@
- {% include "tenders/_closed_badge.html" with tender=tender %} + {% include "tenders/_closed_badge.html" with tender=tender is_new_for_siaes=is_new_for_siaes %}
diff --git a/lemarche/templates/tenders/detail.html b/lemarche/templates/tenders/detail.html index 62ae35514..814befc1a 100644 --- a/lemarche/templates/tenders/detail.html +++ b/lemarche/templates/tenders/detail.html @@ -54,7 +54,7 @@
- {% include "tenders/_detail_card.html" with tender=tender %} + {% include "tenders/_detail_card.html" with tender=tender is_new_for_siaes=is_new_for_siaes %}
diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index d6f702c72..316f5228c 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -1223,6 +1223,37 @@ def test_create_tendersiae_stats_on_tender_view_by_new_user(self): self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) self.assertContains(response, "Déjà 5 prestataires inclusifs") + def test_badge_is_new_for_siaes(self): + # assert the new badge is here + tender_outdated = TenderFactory( + kind=tender_constants.KIND_QUOTE, + author=self.user_buyer_1, + deadline_date=timezone.now() - timedelta(days=1), + ) + self.client.force_login(self.siae_user_1) + url = reverse("tenders:detail", kwargs={"slug": tender_outdated.slug}) + response = self.client.get(url) + self.assertNotContains( + response, 'Nouveau' + ) + + tender_new = TenderFactory( + kind=tender_constants.KIND_QUOTE, + author=self.user_buyer_1, + deadline_date=timezone.now() + timedelta(days=1), + ) + self.client.force_login(self.siae_user_1) + url = reverse("tenders:detail", kwargs={"slug": tender_new.slug}) + response = self.client.get(url) + self.assertContains( + response, 'Nouveau', 1 + ) + + response = self.client.get(url) + self.assertNotContains( + response, 'Nouveau' + ) + class TenderDetailContactClickStatViewTest(TestCase): @classmethod diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 740fd70cc..2214cbd90 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -333,6 +333,8 @@ class TenderDetailView(TenderAuthorOrAdminRequiredIfNotSentMixin, DetailView): model = Tender template_name = "tenders/detail.html" context_object_name = "tender" + is_new_for_siaes: bool = False + object: Tender = None def get(self, request, *args, **kwargs): """ @@ -352,6 +354,8 @@ def get(self, request, *args, **kwargs): if user.kind == User.KIND_SIAE: # user might not be concerned with this tender: we create TenderSiae stats if not user.has_tender_siae(self.object): + # if the user don't have the TenderSiae, the Tender is new + self.is_new_for_siaes = True and not self.object.deadline_date_outdated for siae in user.siaes.all(): TenderSiae.objects.create( tender=self.object, siae=siae, source=tender_constants.TENDER_SIAE_SOURCE_LINK @@ -408,6 +412,7 @@ def get_context_data(self, **kwargs): tender=self.object, siae__in=user.siaes.all(), detail_not_interested_click_date__isnull=False ).exists() ) + context["is_new_for_siaes"] = self.is_new_for_siaes if show_nps: context["nps_form_id"] = settings.TALLY_SIAE_NPS_FORM_ID elif user.kind == User.KIND_PARTNER: