diff --git a/scipost_django/finances/templates/finances/country_level_data.html b/scipost_django/finances/templates/finances/country_level_data.html index ae1812ef9ea3090f4edf36b96ecb87d9a33e37a6..4342e4e7ed6407ee9a1036dddc2ac659b5e27e0e 100644 --- a/scipost_django/finances/templates/finances/country_level_data.html +++ b/scipost_django/finances/templates/finances/country_level_data.html @@ -25,23 +25,25 @@ <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> + <p>Click on flag to view that country's data + {% if 'finadmin' in user_roles %} <span class="ms-4 p-1 text-danger bg-danger bg-opacity-10">[FinAdmin] Ranks and ordering buttons available</span>{% endif %} + </p> <table class="table"> <thead> <tr> - <th colspan="2">Country</th> - <th style="text-align: right;">Expenditures [rank]<br> + <th colspan="3">Country</th> + <th style="text-align: right;">Expenditures{% if 'finadmin' in user_roles %} [rank]<br> <a href="{% url 'finances:country_level_data' %}?ordering=expenditures&reverse=true">{% include 'bi/sort-up.html' %}</a> - <a href="{% url 'finances:country_level_data' %}?ordering=expenditures">{% include 'bi/sort-down.html' %}</a> + <a href="{% url 'finances:country_level_data' %}?ordering=expenditures">{% include 'bi/sort-down.html' %}</a>{% endif %} </th> - <th style="text-align: right;">Subsidy income [rank]<br> + <th style="text-align: right;">Subsidy income{% if 'finadmin' in user_roles %} [rank]<br> <a href="{% url 'finances:country_level_data' %}?ordering=subsidy_income&reverse=true">{% include 'bi/sort-up.html' %}</a> - <a href="{% url 'finances:country_level_data' %}?ordering=subsidy_income">{% include 'bi/sort-down.html' %}</a> + <a href="{% url 'finances:country_level_data' %}?ordering=subsidy_income">{% include 'bi/sort-down.html' %}</a>{% endif %} </th> - <th style="text-align: right;">Impact on reserves [rank]<br> + <th style="text-align: right;">Impact on reserves{% if 'finadmin' in user_roles %} [rank]<br> <a href="{% url 'finances:country_level_data' %}?ordering=impact&reverse=true">{% include 'bi/sort-up.html' %}</a> - <a href="{% url 'finances:country_level_data' %}?ordering=impact">{% include 'bi/sort-down.html' %}</a> + <a href="{% url 'finances:country_level_data' %}?ordering=impact">{% include 'bi/sort-down.html' %}</a>{% endif %} </th> </tr> </thead> @@ -58,15 +60,16 @@ <i class="{{ country_obj.flag_css }}"></i> </a> </td> + <td>{{ country_obj.code }}</td> <td>{{ country_obj.name }}</td> - <td style="text-align: right;">€{{ item.expenditures }} [{{ item.expenditures_rank }}/{{ nr }}]</td> - <td style="text-align: right;">€{{ item.subsidy_income }} [{{ item.subsidy_income_rank }}/{{ nr }}]</td> - <td style="text-align: right;">€{{ item.impact_on_reserves }} [{{ item.impact_on_reserves_rank }}/{{ nr }}]</td> + <td style="text-align: right;">€{{ item.expenditures }}{% if 'finadmin' in user_roles %} [{{ item.expenditures_rank }}/{{ nr }}]{% endif %}</td> + <td style="text-align: right;">€{{ item.subsidy_income }}{% if 'finadmin' in user_roles %} [{{ item.subsidy_income_rank }}/{{ nr }}]{% endif %}</td> + <td style="text-align: right;">€{{ item.impact_on_reserves }}{% if 'finadmin' in user_roles %} [{{ item.impact_on_reserves_rank }}/{{ nr }}]{% endif %}</td> </tr> <tr class="bg-light"> - <td colspan="5"> + <td colspan="6"> <details id="country_data-{{ item.country }}-details" - class="ms-4 mb-4"> + class="ms-4 my-2"> <summary>Toggle details</summary> <div id="country_data-{{ item.country }}-details-contents" class="mt-4 p-2 ps-4" diff --git a/scipost_django/finances/views.py b/scipost_django/finances/views.py index f859482aefda387e22aa73017dc5eb72e0ea11fe..335d3620e7fdbbdade655561909c5783b5299e7c 100644 --- a/scipost_django/finances/views.py +++ b/scipost_django/finances/views.py @@ -243,29 +243,32 @@ def country_level_data(request): countrydatalist += [ countrydata, ] - # Determine the ranks - countrydatalist.sort(key=lambda country: country["expenditures"], reverse=True) - for idx, c in enumerate(countrydatalist): - c["expenditures_rank"] = idx + 1 - countrydatalist.sort(key=lambda country: country["subsidy_income"], reverse=True) - for idx, c in enumerate(countrydatalist): - c["subsidy_income_rank"] = idx + 1 - countrydatalist.sort( - key=lambda country: country["impact_on_reserves"], reverse=True - ) - for idx, c in enumerate(countrydatalist): - c["impact_on_reserves_rank"] = idx + 1 - - ordering = request.GET.get("ordering", None) - reverse_ordering = request.GET.get("reverse", None) - if ordering == "expenditures": - countrydatalist.sort(key=lambda country: country["expenditures"]) - elif ordering == "subsidy_income": - countrydatalist.sort(key=lambda country: country["subsidy_income"]) - elif ordering == "impact": - countrydatalist.sort(key=lambda country: country["impact_on_reserves"]) - if reverse_ordering == "true": - countrydatalist.reverse() + if request.user.has_perm("scipost.can_manage_subsidies"): + # Determine the ranks + countrydatalist.sort(key=lambda country: country["expenditures"], reverse=True) + for idx, c in enumerate(countrydatalist): + c["expenditures_rank"] = idx + 1 + countrydatalist.sort( + key=lambda country: country["subsidy_income"], reverse=True + ) + for idx, c in enumerate(countrydatalist): + c["subsidy_income_rank"] = idx + 1 + countrydatalist.sort( + key=lambda country: country["impact_on_reserves"], reverse=True + ) + for idx, c in enumerate(countrydatalist): + c["impact_on_reserves_rank"] = idx + 1 + + ordering = request.GET.get("ordering", None) + reverse_ordering = request.GET.get("reverse", None) + if ordering == "expenditures": + countrydatalist.sort(key=lambda country: country["expenditures"]) + elif ordering == "subsidy_income": + countrydatalist.sort(key=lambda country: country["subsidy_income"]) + elif ordering == "impact": + countrydatalist.sort(key=lambda country: country["impact_on_reserves"]) + if reverse_ordering == "true": + countrydatalist.reverse() context["countrydata"] = countrydatalist return render(request, "finances/country_level_data.html", context)