Skip to content

Commit a69a20d

Browse files
committed
Add recap for Country Type
1 parent 3755b91 commit a69a20d

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

backend/grants/summary.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def calculate(self, conference_id):
3434
status_totals,
3535
totals_per_continent,
3636
) = self._aggregate_data_by_country(grants_by_country, statuses)
37+
sorted_country_stats = dict(
38+
sorted(country_stats.items(), key=lambda x: (x[0][0], x[0][2]))
39+
)
40+
country_type_summary = self._aggregate_data_by_country_type(
41+
filtered_grants, statuses
42+
)
3743
gender_stats = self._aggregate_data_by_gender(filtered_grants, statuses)
3844
financial_summary, total_amount = self._aggregate_financial_data_by_status(
3945
filtered_grants, statuses
@@ -50,13 +56,13 @@ def calculate(self, conference_id):
5056
requested_needs_summary = self._aggregate_data_by_requested_needs_summary(
5157
filtered_grants, statuses
5258
)
53-
sorted_country_stats = dict(
54-
sorted(country_stats.items(), key=lambda x: (x[0][0], x[0][2]))
55-
)
5659
approved_types = {
5760
approved_type.value: approved_type.label
5861
for approved_type in Grant.ApprovedType
5962
}
63+
country_types = {
64+
country_type.value: country_type.label for country_type in Grant.CountryType
65+
}
6066

6167
return dict(
6268
conference_id=conference_id,
@@ -76,6 +82,8 @@ def calculate(self, conference_id):
7682
approved_type_summary=approved_type_summary,
7783
approved_types=approved_types,
7884
requested_needs_summary=requested_needs_summary,
85+
country_type_summary=country_type_summary,
86+
country_types=country_types,
7987
)
8088

8189
def _aggregate_data_by_country(self, grants_by_country, statuses):
@@ -107,6 +115,26 @@ def _aggregate_data_by_country(self, grants_by_country, statuses):
107115

108116
return summary, status_totals, totals_per_continent
109117

118+
def _aggregate_data_by_country_type(self, filtered_grants, statuses):
119+
"""
120+
Aggregates grant data by country type and status.
121+
"""
122+
country_type_data = filtered_grants.values("country_type", "status").annotate(
123+
total=Count("id")
124+
)
125+
country_type_summary = {
126+
country_type: {status[0]: 0 for status in statuses}
127+
for country_type in Grant.CountryType.values
128+
}
129+
130+
for data in country_type_data:
131+
country_type = data["country_type"]
132+
status = data["status"]
133+
total = data["total"]
134+
country_type_summary[country_type][status] += total
135+
136+
return country_type_summary
137+
110138
def _aggregate_data_by_gender(self, filtered_grants, statuses):
111139
"""
112140
Aggregates grant data by gender and status.

backend/grants/templates/admin/grants/grant_summary.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,36 @@ <h2>by Departure Country</h2>
199199
</tr>
200200
</tfoot>
201201
</table>
202+
<h2>by Departure Country Type</h2>
203+
<table>
204+
<thead>
205+
<tr>
206+
<th>Country Type</th>
207+
<th></th>
208+
{% for status in statuses %}
209+
<th class="status-column-{{ forloop.counter }}"
210+
{% if status.0 not in preselected_statuses %}style="display:none"{% endif %}>
211+
{{ status.1|title }}
212+
</th>
213+
{% endfor %}
214+
</tr>
215+
</thead>
216+
<tbody>
217+
{% for country_type, country_type_data in country_type_summary.items %}
218+
<tr>
219+
<td>{{ country_types|get_item:country_type }}</td>
220+
<td></td>
221+
{% for status in statuses %}
222+
<td class="status-column-{{ forloop.counter }}"
223+
{% if status.0 not in preselected_statuses %}style="display:none"{% endif %}>
224+
{{ country_type_data|get_item:status.0|default:"0" }}
225+
</td>
226+
{% endfor %}
227+
</tr>
228+
{% endfor %}
229+
</tbody>
230+
</table>
231+
202232
<h2>by Gender</h2>
203233
<table>
204234
<thead>

0 commit comments

Comments
 (0)