SciPost Code Repository

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

Add country-level financial data page

parent 2bc4e6ac
No related branches found
No related tags found
No related merge requests found
{% load countries %}
{% 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>
<table class="table">
<thead>
<tr>
<th></th>
<th style="text-align: right;">Contribution</th>
<th style="text-align: right;">Expenditures</th>
<th style="text-align: right;">Balance</th>
</tr>
</thead>
<tbody>
<tr class="bg-light">
<td>Cumulative</td>
<td style="text-align: right;">{{ cumulative.contribution }}</td>
<td style="text-align: right;">{{ cumulative.expenditures }}</td>
<td style="text-align: right;">{{ cumulative.balance }}</td>
</tr>
{% for year, val in per_year.items %}
<tr>
<td>{{ year }}</td>
<td style="text-align: right;">{{ val.contribution }}</td>
<td style="text-align: right;">{{ val.expenditures }}</td>
<td style="text-align: right;">{{ val.balance }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2 class="highlight mt-5">Cumulative, per Organization</h2>
<table class="table">
<thead>
<tr>
<th></th>
<th style="text-align: right;">Contribution</th>
<th style="text-align: right;">Expenditures</th>
<th style="text-align: right;">Balance</th>
</tr>
</thead>
<tbody>
<tr class="bg-light">
<td>Total</td>
<td style="text-align: right;">{{ cumulative.contribution }}</td>
<td style="text-align: right;">{{ cumulative.expenditures }}</td>
<td style="text-align: right;">{{ cumulative.balance }}</td>
</tr>
{% for organization in organizations %}
{% if organization.cf_balance_info.cumulative.contribution > 0 or organization.cf_balance_info.cumulative.expenditures > 0 %}
<tr>
<td><a href="https://{{ request.get_host }}{{ organization.get_absolute_url }}">{{ organization }}</a></td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.contribution }}</td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.expenditures }}</td>
<td style="text-align: right;">{{ organization.cf_balance_info.cumulative.balance }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% extends 'finances/base.html' %}
{% load countries %}
{% load static %}
{% block meta_description %}{{ block.super }} Country balance info{% endblock meta_description %}
{% block pagetitle %}: Country balance info{% endblock pagetitle %}
{% block headsup %}
<link rel="stylesheet" href="{% static 'flags/sprite-hq.css' %}">
{% endblock headsup %}
{% block content %}
<div class="row">
<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>
{% endfor %}
</ul>
</div>
</div>
<div id="country_data" class="mt-4"></div>
</div>
</div>
{% endblock content %}
......@@ -17,6 +17,16 @@ urlpatterns = [
name="business_model",
),
path("apex", views.apex, name="apex"),
path(
"country_level_data",
views.country_level_data,
name="country_level_data",
),
path(
"_hx_country_level_data/<slug:country>",
views._hx_country_level_data,
name="_hx_country_level_data",
),
# Subsidies
path("subsidies/", views.SubsidyListView.as_view(), name="subsidies"),
path("subsidies/add/", views.SubsidyCreateView.as_view(), name="subsidy_create"),
......
......@@ -167,6 +167,51 @@ def apex(request):
return render(request, "finances/apex.html", context)
def country_level_data(request):
context = {}
context["countrycodes"] = [
code["country"]
for code in list(
Organization.objects.all().distinct("country").values("country")
)
]
return render(request, "finances/country_level_data.html", context)
def _hx_country_level_data(request, country):
organizations = Organization.objects.filter(country=country)
pubyears = [str(y) for y in range(int(timezone.now().strftime("%Y")), 2015, -1)]
context = {
"country": country,
"organizations": organizations,
"cumulative": {"contribution": 0, "expenditures": 0, "balance": 0},
"per_year": {}
}
for year in pubyears:
context["per_year"][year] = {
"contribution": 0,
"expenditures": 0,
"balance": 0,
}
cumulative_expenditures = 0
for organization in organizations.all():
for key in ("contribution", "expenditures", "balance"):
context["cumulative"][
key
] += organization.cf_balance_info["cumulative"][key]
for year in pubyears:
context["per_year"][year]["contribution"] += (
organization.cf_balance_info[year]["contribution"]
)
context["per_year"][year]["expenditures"] += (
organization.cf_balance_info[year]["expenditures"]["total"]
)
context["per_year"][year]["balance"] += (
organization.cf_balance_info[year]["balance"]
)
return render(request, "finances/_hx_country_level_data.html", context)
#############
# Subsidies #
#############
......
......@@ -92,7 +92,11 @@
{% for code in countrycodes %}
{% get_country code as country_obj %}
<li style="display: inline-block;">
<a href="{% add_get_parameters country=code %}"><i class="{{ country_obj.flag_css }}" data-bs-toggle="tooltip" title="{{ country_obj.name }}"></i></a>
<a href="{% add_get_parameters country=code %}">
<i class="{{ country_obj.flag_css }}"
data-bs-toggle="tooltip"
title="{{ country_obj.name }}"></i>
</a>
</li>
{% endfor %}
</ul>
......
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