Skip to content

Commit

Permalink
fix details
Browse files Browse the repository at this point in the history
  • Loading branch information
madjid-asa committed Mar 14, 2024
1 parent 1736420 commit f7cd20e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
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
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
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 f7cd20e

Please sign in to comment.