From c4f67e5715eeff6842a270d6d481f72284410830 Mon Sep 17 00:00:00 2001 From: "madjid.asa" Date: Thu, 22 Feb 2024 12:02:44 +0100 Subject: [PATCH 1/3] order by last published tenders on home dashboard siae --- lemarche/tenders/models.py | 3 +++ lemarche/www/dashboard/views.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 23b968be1..0e0520b18 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -183,6 +183,9 @@ def order_by_deadline_date(self, limit_date=datetime.today()): "deadline_date_is_outdated_annotated", "deadline_date", "-updated_at" ) + def order_by_last_published(self): + return self.order_by("-published_at", "-updated_at") + def with_question_stats(self): return self.annotate(question_count_annotated=Count("questions", distinct=True)) diff --git a/lemarche/www/dashboard/views.py b/lemarche/www/dashboard/views.py index ee54a50d6..a3419676d 100644 --- a/lemarche/www/dashboard/views.py +++ b/lemarche/www/dashboard/views.py @@ -65,7 +65,7 @@ def get_context_data(self, **kwargs): if user.kind == User.KIND_SIAE: siaes = user.siaes.all() if siaes: - context["last_3_tenders"] = Tender.objects.filter_with_siaes(siaes).order_by_deadline_date()[:3] + context["last_3_tenders"] = Tender.objects.filter_with_siaes(siaes).order_by_last_published()[:3] else: context["last_3_tenders"] = Tender.objects.filter(author=user).order_by_deadline_date()[:3] context["user_buyer_count"] = User.objects.filter(kind=User.KIND_BUYER).count() From 8d5c940852a15a83a3e12ed1f9cc137bd50f4c15 Mon Sep 17 00:00:00 2001 From: "madjid.asa" Date: Thu, 22 Feb 2024 12:02:53 +0100 Subject: [PATCH 2/3] add tests --- lemarche/tenders/tests.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index 1a24a5dc5..ed9818cdc 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -29,8 +29,10 @@ date_tomorrow = timezone.now() + timedelta(days=1) date_next_week = timezone.now() + timedelta(days=7) +date_today = timezone.now() + timedelta(days=7) date_two_days_ago = timezone.now() - timedelta(days=2) date_last_week = timezone.now() - timedelta(days=7) +date_last_month = timezone.now() - timedelta(days=30) class TenderModelTest(TestCase): @@ -418,9 +420,9 @@ def test_in_perimeters(self): class TenderModelQuerysetOrderTest(TestCase): @classmethod def setUpTestData(cls): - cls.tender_1 = TenderFactory(deadline_date=date_next_week) - cls.tender_2 = TenderFactory(deadline_date=date_tomorrow) - cls.tender_3 = TenderFactory(deadline_date=date_last_week) + cls.tender_1 = TenderFactory(deadline_date=date_next_week, published_at=date_today) + cls.tender_2 = TenderFactory(deadline_date=date_tomorrow, published_at=date_two_days_ago) + cls.tender_3 = TenderFactory(deadline_date=date_last_week, published_at=date_last_month) def test_default_order(self): tender_queryset = Tender.objects.all() @@ -433,6 +435,12 @@ def test_order_by_deadline_date(self): self.assertEqual(tender_queryset.first().id, self.tender_2.id) self.assertEqual(tender_queryset.last().id, self.tender_3.id) + def test_order_by_last_published(self): + tender_queryset = Tender.objects.order_by_last_published() + self.assertEqual(tender_queryset.count(), 3) + self.assertEqual(tender_queryset.first().id, self.tender_1.id) + self.assertEqual(tender_queryset.last().id, self.tender_3.id) + class TenderModelQuerysetStatsTest(TestCase): @classmethod From 9fb11c5b8beb258ffe31094a2ab07ecf914a5920 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Fri, 1 Mar 2024 10:02:45 +0100 Subject: [PATCH 3/3] Fix naming --- lemarche/tenders/tests.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index ed9818cdc..a5627e9c3 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -27,12 +27,12 @@ from lemarche.www.tenders import utils as tender_utils -date_tomorrow = timezone.now() + timedelta(days=1) -date_next_week = timezone.now() + timedelta(days=7) -date_today = timezone.now() + timedelta(days=7) -date_two_days_ago = timezone.now() - timedelta(days=2) -date_last_week = timezone.now() - timedelta(days=7) -date_last_month = timezone.now() - timedelta(days=30) +date_today = timezone.now() +date_tomorrow = date_today + timedelta(days=1) +date_next_week = date_today + timedelta(days=7) +date_two_days_ago = date_today - timedelta(days=2) +date_last_week = date_today - timedelta(days=7) +date_last_month = date_today - timedelta(days=30) class TenderModelTest(TestCase):