diff --git a/lemarche/templates/tenders/_closed_badge.html b/lemarche/templates/tenders/_closed_badge.html index 2db05dd24..58fccf4ca 100644 --- a/lemarche/templates/tenders/_closed_badge.html +++ b/lemarche/templates/tenders/_closed_badge.html @@ -1,4 +1,20 @@ - - {{ tender_kind_display|default:tender.get_kind_display }} clôturé{% if tender.kind == "QUOTE" %}e{% endif %} - le {{ tender.deadline_date|default:"" }} - \ No newline at end of file +

+ {% if tender.deadline_date_is_outdated_annotated %} + + {{ tender_kind_display|default:tender.get_kind_display }} clôturé{% if tender.kind == "QUOTE" %}e{% endif %} + le {{ tender.deadline_date|default:"" }} + + {% else %} + + {% if tender.kind == "PROJ" %} + {{ title_kind_sourcing_siae|default:tender.get_kind_display }} + {% else %} + {{ tender.get_kind_display }} + {% endif %} + + Disponible jusqu'au : {{ tender.deadline_date|default:"" }} + {% if is_new_for_siaes %} + Nouveau + {% endif %} + {% endif %} +

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/_list_item_siae.html b/lemarche/templates/tenders/_list_item_siae.html index 677e4929f..fa58b13b5 100644 --- a/lemarche/templates/tenders/_list_item_siae.html +++ b/lemarche/templates/tenders/_list_item_siae.html @@ -2,22 +2,9 @@
-
-

- {% if tender.deadline_date_is_outdated_annotated %} - Clôturé le {{ tender.deadline_date|default:"" }} - {% else %} - - {% if tender.kind == "PROJ" %} - {{ title_kind_sourcing_siae|default:tender.get_kind_display }} - {% else %} - {{ tender.get_kind_display }} - {% endif %} - - Disponible jusqu'au : {{ tender.deadline_date|default:"" }} - - {% endif %} -

+
+ {% comment %} we set is_new_for_siaes to False because we have other conf in this view {% endcomment %} + {% include "tenders/_closed_badge.html" with tender=tender is_new_for_siaes=False %}
{% if tender.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/tenders/migrations/0081_merge_20240313_1141.py b/lemarche/tenders/migrations/0081_merge_20240313_1141.py new file mode 100644 index 000000000..842af88ed --- /dev/null +++ b/lemarche/tenders/migrations/0081_merge_20240313_1141.py @@ -0,0 +1,12 @@ +# Generated by Django 4.2.9 on 2024-03-13 10:41 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("tenders", "0078_tendersiae_is_deleted_by_siae"), + ("tenders", "0080_tender_siae_transactioned_source_and_more"), + ] + + operations = [] diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index dc187c894..093872043 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -171,7 +171,7 @@ def with_is_new_for_siaes(self, siaes, limit_date=None): # if there's at least one associated TenderSiae (meeting subquery criteria) with a deadline_date # beyond the limit_date. This implies the Tender was introduced after the limit_date, marking it as new. return self.annotate( - is_new_for_siaes=Exists(tender_siae_subquery.filter(tender__deadline_date__gt=limit_date)) + is_new_for_siaes=Exists(tender_siae_subquery.filter(tender__deadline_date__gt=limit_date.date())) ) def filter_with_siaes(self, 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: