SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 38452df2 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Polish up country-level financial data

parent 78c22e4a
No related branches found
No related tags found
No related merge requests found
{% load countries %} {% load countries %}
{% get_country country as country_obj %} {% get_country country as country_obj %}
<h2 class="highlight">Summed over all Organizations in {{ country_obj.name }}&emsp;<i class="{{ country_obj.flag_css }}"></i></h2> <p>The data in this table is compiled by summing over all Organizations in {{ country_obj.name }}&emsp;<i class="{{ country_obj.flag_css }}"></i></p>
<table class="table"> <table class="table">
<thead> <thead>
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<div class="border border-danger p-2"> <div class="border border-danger p-2">
<p><strong>[FinAdmin]</strong></p> <p><strong>[FinAdmin]</strong></p>
<h2 class="highlight mt-5">Cumulative, per Organization</h2> <h2 class="mt-5">Cumulative, per Organization</h2>
<table class="table"> <table class="table">
<thead> <thead>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<td style="text-align: right;">{{ cumulative.expenditures }}</td> <td style="text-align: right;">{{ cumulative.expenditures }}</td>
<td style="text-align: right;">{{ cumulative.balance }}</td> <td style="text-align: right;">{{ cumulative.balance }}</td>
</tr> </tr>
{% for organization in organizations %} {% for organization in organizations|dictsortreversed:"cf_balance_info.cumulative.balance" %}
{% if organization.cf_balance_info.cumulative.subsidy_income > 0 or organization.cf_balance_info.cumulative.expenditures > 0 %} {% if organization.cf_balance_info.cumulative.subsidy_income > 0 or organization.cf_balance_info.cumulative.expenditures > 0 %}
<tr> <tr>
<td><a href="https://{{ request.get_host }}{{ organization.get_absolute_url }}">{{ organization }}</a></td> <td><a href="https://{{ request.get_host }}{{ organization.get_absolute_url }}">{{ organization }}</a></td>
...@@ -69,4 +69,6 @@ ...@@ -69,4 +69,6 @@
</tbody> </tbody>
</table> </table>
</div>
{% endif %} {% endif %}
...@@ -15,29 +15,63 @@ ...@@ -15,29 +15,63 @@
<div class="col-12"> <div class="col-12">
<h2>Country-Level Financial Data</h2> <h2>Country-Level Financial Data</h2>
<div class="row mt-4">
<div class="col-lg-3"> <div id="cumulative_all_countries" class="mt-4">
<h3>Click on flag to view that country's data</h3>
</div> <p>This table presents our cumulative financial balance information, broken down per country. Top of the list are our champions; those at the bottom of the list threaten our sustainability.</p>
<div class="col-lg-8">
<ul> <p>Click on flag to view that country's data</p>
{% for code in countrycodes %}
{% get_country code as country_obj %} <table class="table">
<li style="display: inline-block;" class="m-1"> <thead>
<a hx-get="{% url 'finances:_hx_country_level_data' country=code %}" <tr>
hx-target="#country_data" <th colspan="2">Country</th>
> <th style="text-align: right;">Subsidy income</th>
<i class="{{ country_obj.flag_css }}" <th style="text-align: right;">Expenditures</th>
data-bs-toggle="tooltip" <th style="text-align: right;">Balance</th>
title="{{ country_obj.name }}"></i> </tr>
</a> </thead>
</li> <tbody>
{% for item in countrydata|dictsortreversed:"balance" %}
{% if item.balance != 0 %}
{% get_country item.country as country_obj %}
<tr class="bg-light">
<td>
<a hx-get="{% url 'finances:_hx_country_level_data' country=item.country %}"
hx-target="#country_data-{{ item.country }}"
>
<i class="{{ country_obj.flag_css }}"></i>
</a>
</td>
<td>{{ country_obj.name }}</td>
<td style="text-align: right;">{{ item.subsidy_income }}</td>
<td style="text-align: right;">{{ item.expenditures }}</td>
<td style="text-align: right;">{{ item.balance }}</td>
</tr>
<tr>
<td colspan="5">
<details id="country_data-{{ item.country }}-details"
class="ms-4 mb-4">
<summary>Toggle details</summary>
<div id="country_data-{{ item.country }}-details-contents"
class="mt-4 p-2 ps-4"
hx-get="{% url 'finances:_hx_country_level_data' country=item.country %}"
hx-trigger="toggle once from:#country_data-{{ item.country }}-details"
>
<button class="htmx-indicator btn btn-sm btn-warning p-2" type="button" disabled>
<small><strong>Loading...</strong></small>
<div class="spinner-grow spinner-grow-sm ms-2" role="status" aria-hidden="true"></div>
</button>
</div>
</details>
</td>
</tr>
{% endif %}
{% endfor %} {% endfor %}
</ul> </tbody>
</div> </table>
</div>
<div id="country_data" class="mt-4"></div> </div>
</div> </div>
</div> </div>
......
...@@ -216,12 +216,23 @@ def apex(request): ...@@ -216,12 +216,23 @@ def apex(request):
def country_level_data(request): def country_level_data(request):
context = {} context = {}
context["countrycodes"] = [ countrycodes = [
code["country"] code["country"]
for code in list( for code in list(
Organization.objects.all().distinct("country").values("country") Organization.objects.all().distinct("country").values("country")
) )
] ]
context = {
"countrycodes": countrycodes,
"countrydata": [],
}
for country in countrycodes:
country_organizations = Organization.objects.filter(country=country)
countrydata = {"country": country, "subsidy_income": 0, "expenditures": 0, "balance": 0}
for organization in country_organizations:
for key in ("subsidy_income", "expenditures", "balance"):
countrydata[key] += organization.cf_balance_info["cumulative"][key]
context["countrydata"] += [countrydata,]
return render(request, "finances/country_level_data.html", context) return render(request, "finances/country_level_data.html", context)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment