Skip to content

Commit

Permalink
Add totals for export win status.
Browse files Browse the repository at this point in the history
  • Loading branch information
elcct committed Jan 23, 2025
1 parent 5675321 commit 7be5ef9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.17 on 2025-01-23 08:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('export_win', '0056_update_export_experience'),
]

operations = [
migrations.AlterField(
model_name='customerresponse',
name='agree_with_win',
field=models.BooleanField(db_index=True, null=True, verbose_name='Please confirm these details are correct'),
),
]
1 change: 1 addition & 0 deletions datahub/export_win/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ class CustomerResponse(BaseModel):
agree_with_win = models.BooleanField(
null=True,
verbose_name='Please confirm these details are correct',
db_index=True,
)
case_study_willing = models.BooleanField(
verbose_name=('Would you be willing for DBT/Exporting is GREAT to feature your success '
Expand Down
4 changes: 4 additions & 0 deletions datahub/export_win/test/test_win_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ def test_list_with_legacy_wins(self):
response_data = response.json()

assert response_data['count'] == 4
assert sum(response_data['confirmed'].values()) == 4

def test_list_default_sorting(self):
"""Tests wins are sorted."""
Expand Down Expand Up @@ -529,6 +530,9 @@ def test_list_filtered_by_agree_with_win(self, export_wins, confirmed, results_l
results = response.json()

assert len(results['results']) == results_length
assert results['confirmed'][confirmed] == results_length
# Totals are unaffected by filtering
assert sum(results['confirmed'].values()) == 6

expected = {
'true': True,
Expand Down
14 changes: 13 additions & 1 deletion datahub/export_win/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime

from django.conf import settings
from django.db.models import Max, Min, Q
from django.db.models import Case, Count, Max, Min, Q, Value, When

from django.http import Http404
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -176,6 +176,18 @@ def retrieve(self, request, *args, **kwargs):
serializer = self.get_serializer(win)
return Response(serializer.data)

def list(self, request, *args, **kwargs):
response = super().list(request, *args, **kwargs)

# include totals for each Win status
counts = Win.objects.aggregate(
null=Count(Case(When(customer_response__agree_with_win__isnull=True, then=Value(1)))),
true=Count(Case(When(customer_response__agree_with_win=True, then=Value(1)))),
false=Count(Case(When(customer_response__agree_with_win=False, then=Value(1)))),
)
response.data.update({'confirmed': counts})
return response

@action(methods=['post'], detail=True, schema=StubSchema())
def resend_export_win(self, request, *args, **kwargs):
"""
Expand Down

0 comments on commit 7be5ef9

Please sign in to comment.