Skip to content

Commit

Permalink
remove new badge on outdated tender
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Feb 19, 2024
1 parent 949cb4c commit bf17c50
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lemarche/templates/tenders/_list_item_siae.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
{% endif %}
</span>
Disponible <strong>jusqu'au : {{ tender.deadline_date|default:"" }}</strong>
{% endif %}
{% if not tender.tendersiae_set.first.detail_display_date %}
<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>
{% if not tender.tendersiae_set.first.detail_display_date %}
<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>
{% endif %}
{% endif %}
</p>
</div>
Expand Down
9 changes: 6 additions & 3 deletions lemarche/users/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from django.conf import settings
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractUser
Expand Down Expand Up @@ -364,9 +366,10 @@ def has_tender_siae(self, tender=None):
def tender_siae_unread_count(self):
from lemarche.tenders.models import TenderSiae

qs = TenderSiae.objects.filter(siae__in=self.siaes.all(), tender__validated_at__isnull=False).filter(
detail_display_date__isnull=True
)
limit_date = datetime.today()
qs = TenderSiae.objects.filter(
siae__in=self.siaes.all(), tender__validated_at__isnull=False, tender__deadline_date__gt=limit_date
).filter(detail_display_date__isnull=True)
return qs.count()


Expand Down
19 changes: 13 additions & 6 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ def setUpTestData(cls):
email_send_date=timezone.now(),
detail_contact_click_date=timezone.now(),
)
cls.tender_4 = TenderFactory(author=cls.user_buyer_1, perimeters=[perimeter])
cls.tendersiae_4_1 = TenderSiae.objects.create(
tender=cls.tender_4, siae=cls.siae_1, email_send_date=timezone.now()
)

def test_anonymous_user_cannot_list_tenders(self):
url = reverse("tenders:list")
Expand All @@ -511,8 +515,9 @@ def test_siae_user_should_see_matching_tenders(self):
url = reverse("tenders:list")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["tenders"]), 1)
self.assertEqual(len(response.context["tenders"]), 2)
self.assertContains(response, self.tender_3.title)
self.assertContains(response, self.tender_4.title)
self.assertContains(response, "Entreprise Buyer")
self.assertNotContains(response, "K€") # !accept_share_amount
self.assertNotContains(response, "2 prestataires ciblés") # tender_3, but only visible to author
Expand All @@ -523,7 +528,7 @@ def test_buyer_user_should_only_see_his_tenders(self):
url = reverse("tenders:list")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["tenders"]), 3)
self.assertEqual(len(response.context["tenders"]), 4)
self.assertContains(response, "2 prestataires ciblés") # tender_3
self.assertContains(response, "1 prestataire intéressé") # tender_3
self.assertNotContains(response, "Demandes reçues")
Expand Down Expand Up @@ -551,14 +556,16 @@ def test_siae_user_should_see_unread_badge(self):
url = reverse("tenders:list")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["tenders"]), 1)
# The badge in header
self.assertEqual(len(response.context["tenders"]), 2)
# The badge in header, only one because one is outdated
self.assertContains(response, 'Demandes reçues <span class="badge badge-pill badge-important fs-xs">1</span>')
# The badge in tender list
self.assertContains(response, '<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>')
self.assertContains(
response, '<span class="float-right badge badge-sm badge-pill badge-new">Nouveau</span>', 1
)

# Open tender detail page
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender_3.slug})
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender_4.slug})
self.client.get(detail_url)

# The badges have disappeared
Expand Down

0 comments on commit bf17c50

Please sign in to comment.