Skip to content

Commit

Permalink
fix(Dépôt de besoin): Réparation du badge de clôture (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
madjid-asa authored Mar 14, 2024
1 parent 4404359 commit af0bd82
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 23 deletions.
24 changes: 20 additions & 4 deletions lemarche/templates/tenders/_closed_badge.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<span class="badge badge-xs badge-base badge-pill badge-{{ tender.kind|lower }}">
{{ tender_kind_display|default:tender.get_kind_display }} clôturé{% if tender.kind == "QUOTE" %}e{% endif %}
le {{ tender.deadline_date|default:"" }}
</span>
<p class="mb-1">
{% if tender.deadline_date_is_outdated_annotated %}
<span class="badge badge-xs badge-base badge-pill badge-{{ tender.kind|lower }}">
{{ tender_kind_display|default:tender.get_kind_display }} clôturé{% if tender.kind == "QUOTE" %}e{% endif %}
le {{ tender.deadline_date|default:"" }}
</span>
{% else %}
<span class="badge badge-base badge-pill mr-1 badge-{{ tender.kind|lower }}">
{% if tender.kind == "PROJ" %}
{{ title_kind_sourcing_siae|default:tender.get_kind_display }}
{% else %}
{{ tender.get_kind_display }}
{% endif %}
</span>
Disponible <strong>jusqu'au : {{ tender.deadline_date|default:"" }}</strong>
{% if is_new_for_siaes %}
<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>
{% endif %}
{% endif %}
</p>
2 changes: 1 addition & 1 deletion lemarche/templates/tenders/_detail_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="card c-card c-card--marche siae-card rounded-lg shadow-lg">
<div class="card-header fs-sm rounded-top rounded-lg px-5">
{% include "tenders/_closed_badge.html" with tender=tender %}
{% include "tenders/_closed_badge.html" with tender=tender is_new_for_siaes=is_new_for_siaes %}
</div>
<div class="card-body pb-5 px-5">
<!-- title & header -->
Expand Down
19 changes: 3 additions & 16 deletions lemarche/templates/tenders/_list_item_siae.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,9 @@
<div id="card-{{tender.slug}}" class="card c-card c-card--marche-{{ tender.kind|lower }}{% if tender.deadline_date_is_outdated_annotated %} c-card--marche-outdated{% endif %} mb-2">
<div class="card-body">
<div class="row">
<div class="col-md-9">
<p class="mb-1">
{% if tender.deadline_date_is_outdated_annotated %}
<span class="badge badge-sm badge-base badge-pill badge-nuance-08">Clôturé le {{ tender.deadline_date|default:"" }}</span>
{% else %}
<span class="badge badge-base badge-pill mr-1 badge-{{ tender.kind|lower }}">
{% if tender.kind == "PROJ" %}
{{ title_kind_sourcing_siae|default:tender.get_kind_display }}
{% else %}
{{ tender.get_kind_display }}
{% endif %}
</span>
Disponible <strong>jusqu'au : {{ tender.deadline_date|default:"" }}</strong>

{% endif %}
</p>
<div class="col-md-12">
{% 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 %}
</div>
<div class="col-md-3">
{% if tender.is_new_for_siaes %}
Expand Down
2 changes: 1 addition & 1 deletion lemarche/templates/tenders/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<div class="row">
<!-- Main tender card -->
<div class="col-12 col-lg-8 order-2">
{% include "tenders/_detail_card.html" with tender=tender %}
{% include "tenders/_detail_card.html" with tender=tender is_new_for_siaes=is_new_for_siaes %}
</div>
<!-- Sidebar with actions -->
<div class="col-12 col-lg-4 order-1 order-lg-2">
Expand Down
12 changes: 12 additions & 0 deletions lemarche/tenders/migrations/0081_merge_20240313_1141.py
Original file line number Diff line number Diff line change
@@ -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 = []
2 changes: 1 addition & 1 deletion lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
31 changes: 31 additions & 0 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>'
)

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, '<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>', 1
)

response = self.client.get(url)
self.assertNotContains(
response, '<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>'
)


class TenderDetailContactClickStatViewTest(TestCase):
@classmethod
Expand Down
5 changes: 5 additions & 0 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit af0bd82

Please sign in to comment.