From 38452df289fd46235484153bce487ae2999ae884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Thu, 21 Mar 2024 09:17:10 +0100 Subject: [PATCH] Polish up country-level financial data --- .../finances/_hx_country_level_data.html | 8 +- .../finances/country_level_data.html | 76 ++++++++++++++----- scipost_django/finances/views.py | 13 +++- 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/scipost_django/finances/templates/finances/_hx_country_level_data.html b/scipost_django/finances/templates/finances/_hx_country_level_data.html index 66b83b91f..41a33d121 100644 --- a/scipost_django/finances/templates/finances/_hx_country_level_data.html +++ b/scipost_django/finances/templates/finances/_hx_country_level_data.html @@ -1,7 +1,7 @@ {% load countries %} {% get_country country as country_obj %} -<h2 class="highlight">Summed over all Organizations in {{ country_obj.name }} <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 }} <i class="{{ country_obj.flag_css }}"></i></p> <table class="table"> <thead> @@ -35,7 +35,7 @@ <div class="border border-danger p-2"> <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"> <thead> @@ -55,7 +55,7 @@ <td style="text-align: right;">{{ cumulative.expenditures }}</td> <td style="text-align: right;">{{ cumulative.balance }}</td> </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 %} <tr> <td><a href="https://{{ request.get_host }}{{ organization.get_absolute_url }}">{{ organization }}</a></td> @@ -69,4 +69,6 @@ </tbody> </table> + </div> + {% endif %} diff --git a/scipost_django/finances/templates/finances/country_level_data.html b/scipost_django/finances/templates/finances/country_level_data.html index 5bde18935..2ad35767e 100644 --- a/scipost_django/finances/templates/finances/country_level_data.html +++ b/scipost_django/finances/templates/finances/country_level_data.html @@ -15,29 +15,63 @@ <div class="col-12"> <h2>Country-Level Financial Data</h2> - <div class="row mt-4"> - <div class="col-lg-3"> - <h3>Click on flag to view that country's data</h3> - </div> - <div class="col-lg-8"> - <ul> - {% for code in countrycodes %} - {% get_country code as country_obj %} - <li style="display: inline-block;" class="m-1"> - <a hx-get="{% url 'finances:_hx_country_level_data' country=code %}" - hx-target="#country_data" - > - <i class="{{ country_obj.flag_css }}" - data-bs-toggle="tooltip" - title="{{ country_obj.name }}"></i> - </a> - </li> + + <div id="cumulative_all_countries" class="mt-4"> + + <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> + + <p>Click on flag to view that country's data</p> + + <table class="table"> + <thead> + <tr> + <th colspan="2">Country</th> + <th style="text-align: right;">Subsidy income</th> + <th style="text-align: right;">Expenditures</th> + <th style="text-align: right;">Balance</th> + </tr> + </thead> + <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 %} - </ul> - </div> - </div> + </tbody> + </table> - <div id="country_data" class="mt-4"></div> + </div> </div> </div> diff --git a/scipost_django/finances/views.py b/scipost_django/finances/views.py index fd6270a58..96b0d5514 100644 --- a/scipost_django/finances/views.py +++ b/scipost_django/finances/views.py @@ -216,12 +216,23 @@ def apex(request): def country_level_data(request): context = {} - context["countrycodes"] = [ + countrycodes = [ code["country"] for code in list( 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) -- GitLab