Skip to content

Commit

Permalink
Tender: add stat siae_email_link_click_or_detail_display_count
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Sep 28, 2023
1 parent 9278b47 commit 6eefd26
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
17 changes: 17 additions & 0 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
# "siae_email_send_count_with_link",
"siae_email_link_click_count_with_link",
"siae_detail_display_count_with_link",
# "siae_email_link_click_or_detail_display_count_with_link",
"siae_detail_contact_click_count_with_link",
"siae_transactioned",
"created_at",
Expand Down Expand Up @@ -176,6 +177,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"siae_email_send_count_with_link",
"siae_email_link_click_count_with_link",
"siae_detail_display_count_with_link",
"siae_email_link_click_or_detail_display_count_with_link",
"siae_detail_contact_click_count_with_link",
"logs_display",
"extra_data_display",
Expand Down Expand Up @@ -281,6 +283,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"siae_email_send_count_with_link",
"siae_email_link_click_count_with_link",
"siae_detail_display_count_with_link",
"siae_email_link_click_or_detail_display_count_with_link",
"siae_detail_contact_click_count_with_link",
)
},
Expand Down Expand Up @@ -446,6 +449,20 @@ def siae_detail_display_count_with_link(self, tender):
siae_detail_display_count_with_link.short_description = "S. vues"
siae_detail_display_count_with_link.admin_order_field = "siae_detail_display_count"

def siae_email_link_click_or_detail_display_count_with_link(self, tender):
url = (
reverse("admin:siaes_siae_changelist")
+ f"?tenders__in={tender.id}&tendersiae__detail_display_date__isnull=False"
)
return format_html(
f'<a href="{url}">{getattr(tender, "siae_email_link_click_or_detail_display_count", 0)}</a>'
)

siae_email_link_click_or_detail_display_count_with_link.short_description = "S. cliquées ou vues"
siae_email_link_click_or_detail_display_count_with_link.admin_order_field = (
"siae_email_link_click_or_detail_display_count"
)

def siae_detail_contact_click_count_with_link(self, tender):
url = (
reverse("admin:siaes_siae_changelist")
Expand Down
22 changes: 11 additions & 11 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def with_siae_stats(self):
When(tendersiae__detail_display_date__isnull=False, then=1), default=0, output_field=IntegerField()
)
),
siae_email_link_click_or_detail_display_count=Sum(
Case(
When(
Q(tendersiae__detail_display_date__isnull=False)
| Q(tendersiae__detail_display_date__isnull=False),
then=1,
),
default=0,
output_field=IntegerField(),
)
),
siae_detail_contact_click_count=Sum(
Case(
When(tendersiae__detail_contact_click_date__isnull=False, then=1),
Expand Down Expand Up @@ -555,17 +566,6 @@ def hubspot_deal_id(self):
def siae_detail_display_date_count(self):
return self.tendersiae_set.filter(detail_display_date__isnull=False).count()

@property
def siae_detail_display_date_count_all(self):
"""
Return all siae that have seen the tender (via e-mail or link or both)
"""
return (
self.tendersiae_set.filter(Q(email_link_click_date__isnull=False) | Q(detail_display_date__isnull=False))
.distinct()
.count()
)

@property
def siae_email_send_date_count(self):
return self.tendersiae_set.filter(email_send_date__isnull=False).count()
Expand Down
4 changes: 4 additions & 0 deletions lemarche/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,23 @@ def test_with_siae_stats_queryset(self):
self.assertEqual(tender_with_siae_1.siae_email_send_count, 4)
self.assertEqual(tender_with_siae_1.siae_email_link_click_count, 3)
self.assertEqual(tender_with_siae_1.siae_detail_display_count, 2)
self.assertEqual(tender_with_siae_1.siae_email_link_click_or_detail_display_count, 2)
self.assertEqual(tender_with_siae_1.siae_detail_contact_click_count, 1)
self.assertEqual(tender_with_siae_1.siae_detail_contact_click_since_last_seen_date_count, 1)
tender_with_siae_2 = Tender.objects.with_siae_stats().filter(id=self.tender_with_siae_2.id).first()
self.assertEqual(tender_with_siae_2.siaes.count(), 1)
self.assertEqual(tender_with_siae_2.siae_count, 1)
self.assertEqual(tender_with_siae_2.siae_email_send_count, 1)
self.assertEqual(tender_with_siae_2.siae_detail_display_count, 1)
self.assertEqual(tender_with_siae_2.siae_email_link_click_or_detail_display_count, 1)
self.assertEqual(tender_with_siae_2.siae_detail_contact_click_count, 1)
self.assertEqual(tender_with_siae_2.siae_detail_contact_click_since_last_seen_date_count, 1)
tender_without_siae = Tender.objects.with_siae_stats().filter(id=self.tender_without_siae.id).first()
self.assertEqual(tender_without_siae.siaes.count(), 0)
self.assertEqual(tender_without_siae.siae_count, 0)
self.assertEqual(tender_without_siae.siae_email_send_count, 0)
self.assertEqual(tender_without_siae.siae_detail_display_count, 0)
self.assertEqual(tender_without_siae.siae_email_link_click_or_detail_display_count, 0)
self.assertEqual(tender_without_siae.siae_detail_contact_click_count, 0)
self.assertEqual(tender_without_siae.siae_detail_contact_click_since_last_seen_date_count, 0)

Expand Down Expand Up @@ -367,6 +370,7 @@ def test_with_deadline_date_is_outdated_queryset(self):
# self.assertEqual(tender_with_siae_1.siae_email_send_count, 4)
# self.assertEqual(tender_with_siae_1.siae_email_link_click_count, 3)
# self.assertEqual(tender_with_siae_1.siae_detail_display_count, 2)
# self.assertEqual(tender_with_siae_1.siae_email_link_click_or_detail_display_count, 2)
# self.assertEqual(tender_with_siae_1.siae_detail_contact_click_count, 1)
# self.assertEqual(tender_with_siae_1.siae_detail_contact_click_since_last_seen_date_count, 1)

Expand Down

0 comments on commit 6eefd26

Please sign in to comment.