From b8499bcfc0321a3f7176ef784997c8cd82564a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org> Date: Mon, 18 Mar 2024 05:45:24 +0100 Subject: [PATCH] Tweak display of subsidy totals in organization detail page --- scipost_django/organizations/models.py | 13 ++++++++++++- .../templates/organizations/_organization_card.html | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/scipost_django/organizations/models.py b/scipost_django/organizations/models.py index ec53cb080..22e8d3bd7 100644 --- a/scipost_django/organizations/models.py +++ b/scipost_django/organizations/models.py @@ -440,7 +440,7 @@ class Organization(models.Model): total += subsidy.value_in_year(year) return total - def get_total_subsidies_obtained(self, n_years_past=None): + def get_total_subsidies_obtained(self): """ Computes the total amount received by SciPost, in the form of subsidies from this Organization. @@ -451,6 +451,17 @@ class Organization(models.Model): .get("amount__sum", 0) ) + def get_total_subsidies_publicly_shown(self): + """ + Computes the total amount of publicly visible Subsidies. + """ + return ( + self.subsidy_set.obtained() + .filter(amount_publicly_shown=True) + .aggregate(models.Sum("amount")) + .get("amount__sum", 0) + ) + def get_balance_info(self): """ Return a dict containing this Organization's expenditure and support history. diff --git a/scipost_django/organizations/templates/organizations/_organization_card.html b/scipost_django/organizations/templates/organizations/_organization_card.html index 7269ce906..001fb5e2e 100644 --- a/scipost_django/organizations/templates/organizations/_organization_card.html +++ b/scipost_django/organizations/templates/organizations/_organization_card.html @@ -231,7 +231,13 @@ {% endfor %} <tr style="border-top: 2px solid black"> <td>Total support obtained:</td> - <td>{% if subsidy.amount_publicly_shown or perms.scipost.can_manage_subsidies or "can_view_org_contacts" in user_org_perms %}€{{ org.get_total_subsidies_obtained }}{% else %}-{% endif %}</td> + <td> + {% with org.get_total_subsidies_publicly_shown as total_subsidies %} + {% if total_subsidies %} + €{{ total_subsidies }} + {% else %}-{% endif %} + {% endwith %} + </td> <td></td> </tr> </tbody> -- GitLab