From 24511a87207b74d65916aa47496d6fba4d2fef07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Fri, 8 Mar 2024 12:17:52 +0100 Subject: [PATCH] rename count key --- lemarche/tenders/models.py | 6 ++++-- lemarche/tenders/tests.py | 10 +++++----- lemarche/www/tenders/forms.py | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index c49479ecc..6a4af88c4 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -908,10 +908,12 @@ def detail_contact_click_post_reminder(self, gte_days_ago, lt_days_ago): detail_contact_click_date__lt=lt_days_ago ) - def unread_counts(self, user): + def unread_stats(self, user): limit_date = datetime.today() aggregates = { - f"count_{kind}": Count(Case(When(tender__kind=kind, then=1), output_field=IntegerField()), distinct=True) + f"unread_count_{kind}_annotated": Count( + Case(When(tender__kind=kind, then=1), output_field=IntegerField()), distinct=True + ) for kind, _ in tender_constants.KIND_CHOICES } return ( diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index e04895afb..7905d4d2c 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -832,11 +832,11 @@ def test_detail_contact_click_post_reminder(self): 1, ) - def test_unread_counts(self): - counts = TenderSiae.objects.unread_counts(user=self.user_siae) - self.assertEqual(counts[f"count_{tender_constants.KIND_TENDER}"], 1) - self.assertEqual(counts[f"count_{tender_constants.KIND_QUOTE}"], 1) - self.assertEqual(counts[f"count_{tender_constants.KIND_PROJECT}"], 0) + def test_unread_stats(self): + stats = TenderSiae.objects.unread_stats(user=self.user_siae) + self.assertEqual(stats[f"unread_count_{tender_constants.KIND_TENDER}_annotated"], 1) + self.assertEqual(stats[f"unread_count_{tender_constants.KIND_QUOTE}_annotated"], 1) + self.assertEqual(stats[f"unread_count_{tender_constants.KIND_PROJECT}_annotated"], 0) class TenderAdminTest(TestCase): diff --git a/lemarche/www/tenders/forms.py b/lemarche/www/tenders/forms.py index 30fc39df1..4f4ef6424 100644 --- a/lemarche/www/tenders/forms.py +++ b/lemarche/www/tenders/forms.py @@ -365,12 +365,12 @@ class TenderFilterForm(forms.Form): def __init__(self, user, *args, **kwargs): super().__init__(*args, **kwargs) - counts = TenderSiae.objects.unread_counts(user=user) + stats = TenderSiae.objects.unread_stats(user=user) new_choices = [] for kind_key, kind_label in self.FORM_KIND_CHOICES: - count_key = f"count_{kind_key}" - if count_key in counts and counts[count_key] > 0: - new_choices.append((kind_key, f"{kind_label} ({counts[count_key]})")) + count_key = f"unread_count_{kind_key}_annotated" + if count_key in stats and stats[count_key] > 0: + new_choices.append((kind_key, f"{kind_label} ({stats[count_key]})")) else: new_choices.append((kind_key, kind_label))