Skip to content

Commit f04e76f

Browse files
committed
Add summary by occupation to grant summary
1 parent a69a20d commit f04e76f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

backend/grants/summary.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def calculate(self, conference_id):
6363
country_types = {
6464
country_type.value: country_type.label for country_type in Grant.CountryType
6565
}
66+
occupation_summary = self._aggregate_data_by_occupation(
67+
filtered_grants, statuses
68+
)
6669

6770
return dict(
6871
conference_id=conference_id,
@@ -84,6 +87,7 @@ def calculate(self, conference_id):
8487
requested_needs_summary=requested_needs_summary,
8588
country_type_summary=country_type_summary,
8689
country_types=country_types,
90+
occupation_summary=occupation_summary,
8791
)
8892

8993
def _aggregate_data_by_country(self, grants_by_country, statuses):
@@ -291,3 +295,23 @@ def _aggregate_data_by_requested_needs_summary(self, filtered_grants, statuses):
291295
requested_needs_summary[field][status] += total
292296

293297
return requested_needs_summary
298+
299+
def _aggregate_data_by_occupation(self, filtered_grants, statuses):
300+
"""
301+
Aggregates grant data by occupation and status.
302+
"""
303+
occupation_data = filtered_grants.values("occupation", "status").annotate(
304+
total=Count("id")
305+
)
306+
occupation_summary = {
307+
occupation: {status[0]: 0 for status in statuses}
308+
for occupation in Grant.Occupation.values
309+
}
310+
311+
for data in occupation_data:
312+
occupation = data["occupation"]
313+
status = data["status"]
314+
total = data["total"]
315+
occupation_summary[occupation][status] += total
316+
317+
return occupation_summary

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,35 @@ <h2>by Requested Needs</h2>
387387
{% endfor %}
388388
</tbody>
389389
</table>
390+
<h2>by Occupation</h2>
391+
<table>
392+
<thead>
393+
<tr>
394+
<th>Occupation</th>
395+
<th></th>
396+
{% for status in statuses %}
397+
<th class="status-column-{{ forloop.counter }}"
398+
{% if status.0 not in preselected_statuses %}style="display:none"{% endif %}>
399+
{{ status.1|title }}
400+
</th>
401+
{% endfor %}
402+
</tr>
403+
</thead>
404+
<tbody>
405+
{% for occupation, occupation_data in occupation_summary.items %}
406+
<tr>
407+
<td>{{ occupation|title }}</td>
408+
<td></td>
409+
{% for status in statuses %}
410+
<td class="status-column-{{ forloop.counter }}"
411+
{% if status.0 not in preselected_statuses %}style="display:none"{% endif %}>
412+
{{ occupation_data|get_item:status.0|default:"0" }}
413+
</td>
414+
{% endfor %}
415+
</tr>
416+
{% endfor %}
417+
</tbody>
418+
</table>
390419
</div>
391420
<script>
392421
document.addEventListener('DOMContentLoaded', function() {

0 commit comments

Comments
 (0)