diff --git a/scipost_django/SciPost_v1/settings/base.py b/scipost_django/SciPost_v1/settings/base.py index 53d1484f84949722f391141756fd1e6620ca9356..816ac2562496348c9f1ef72b6c6a635be79648df 100644 --- a/scipost_django/SciPost_v1/settings/base.py +++ b/scipost_django/SciPost_v1/settings/base.py @@ -335,6 +335,7 @@ TEMPLATES = [ "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", "scipost.context_processors.roles_processor", + "journals.context_processors.publishing_years_processor", "journals.context_processors.journals_processor", "ontology.context_processors.ontology_processor", ], diff --git a/scipost_django/finances/views.py b/scipost_django/finances/views.py index b9aa1a6abb95d5bc50d7ee40dbefb5b39be51df9..d916ac7f841e5c459a02a6d821daed9dfd6378fc 100644 --- a/scipost_django/finances/views.py +++ b/scipost_django/finances/views.py @@ -240,7 +240,6 @@ def _hx_country_level_data(request, country): "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"][ diff --git a/scipost_django/journals/context_processors.py b/scipost_django/journals/context_processors.py index 1c9770dae39b7861cbe26c58f069f5e4aa41d947..6771d622e22b6ecb2c71bf286391630eec168dd2 100644 --- a/scipost_django/journals/context_processors.py +++ b/scipost_django/journals/context_processors.py @@ -2,7 +2,18 @@ __copyright__ = "Copyright 2016-2018, Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" from ontology.models import Branch, AcademicField -from .models import Journal +from .models import Journal, Publication + + +def publishing_years_processor(request): + """List of years where publishing activity took place, going backwards in time.""" + return { + "publishing_years": range( + Publication.objects.published().first().publication_date.year, + Publication.objects.published().last().publication_date.year, + -1, + ) + } def journals_processor(request): diff --git a/scipost_django/organizations/templates/organizations/_organization_card.html b/scipost_django/organizations/templates/organizations/_organization_card.html index 99a96cecb56f8ed0a9e4fd04869c0edeb363f035..55bc30c46c63d5e6214139d5ecb15bdf3259a13a 100644 --- a/scipost_django/organizations/templates/organizations/_organization_card.html +++ b/scipost_django/organizations/templates/organizations/_organization_card.html @@ -76,7 +76,7 @@ <h3>Publications associated to this Organization {% if perms.scipost.can_manage_organizations %} <span class="text-muted small">(with PubFracs <span data-bs-toggle="tooltip" data-bs-html="true" title="" data-original-title="Fraction of a publication's funding/institutional support associated to a given Organization">{% include 'bi/info-circle-fill.html' %}</span>)</span>{% endif %}:</h3> - {% for pubyear in pubyears %} + {% for pubyear in publishing_years %} <h4>{{ pubyear }}{% if perms.scipost.can_manage_organizations %} <span class="text-muted small">(PubFracs {{ org|pubfracs_in_year:pubyear }})</span>{% endif %}</h4> <ul> {% for publication in org.get_publications %} @@ -332,7 +332,7 @@ {% endif %} </tr> {% now "Y" as current_year %} - {% for year in pubyears %} + {% for year in publishing_years %} {% for key, val in balance.items %} {% if year == key|add:"0" %} <tr> diff --git a/scipost_django/organizations/templates/organizations/organization_detail.html b/scipost_django/organizations/templates/organizations/organization_detail.html index 98cb86394b9e76b684d16431ee71e658a8de7f42..408f68fc00a4dba10050dd309c8a4f6b2ce334f3 100644 --- a/scipost_django/organizations/templates/organizations/organization_detail.html +++ b/scipost_django/organizations/templates/organizations/organization_detail.html @@ -40,7 +40,7 @@ <div class="row"> <div class="col-12"> - {% include 'organizations/_organization_card.html' with org=organization pubyears=pubyears %} + {% include 'organizations/_organization_card.html' with org=organization %} </div> </div> diff --git a/scipost_django/organizations/templates/organizations/organization_list.html b/scipost_django/organizations/templates/organizations/organization_list.html index 3278e0a7fc6ed1be67963306b9fbac6d8b0af6ce..d66e2285ee833b19f67eef7405c31454c8fb3efe 100644 --- a/scipost_django/organizations/templates/organizations/organization_list.html +++ b/scipost_django/organizations/templates/organizations/organization_list.html @@ -123,6 +123,9 @@ {% endif %} </th> <th>SciPost sponsor?</th> + {% if 'finadmin' in user_roles %} + <th class="bg-danger bg-opacity-10"><span class="text-danger">FinAdmin</span><br>Support balance</th> + {% endif %} </tr> </thead> <tbody> @@ -156,6 +159,26 @@ {% else %} <td class="bg-warning">Not yet</td> {% endif %} + {% if 'finadmin' in user_roles %} + <td> + <table> + <tr> + <td class="py-0">cumul.:</td> + <td class="py-0 text-end">€{{ org.cf_balance_info.cumulative.balance }}</td> + </tr> + {% for year in publishing_years|slice:"0:5" %} + {% for key, val in org.cf_balance_info.items %} + {% if year == key|add:"0" %} + <tr> + <td class="py-0">{{ year }}:</td> + <td class="py-0 text-end">€{{ val.balance }}</td> + </tr> + {% endif %} + {% endfor %} + {% endfor %} + </table> + </td> + {% endif %} </tr> {% empty %} <tr><td colspan="4">No organizations found</td></tr> diff --git a/scipost_django/organizations/views.py b/scipost_django/organizations/views.py index 75ee133a8e0a31731804a1e2ffe28a36a4d93302..c78ad7648e22539c86c559fe31eba4e3bf2f6472 100644 --- a/scipost_django/organizations/views.py +++ b/scipost_django/organizations/views.py @@ -143,7 +143,6 @@ class OrganizationListView(PaginationMixin, ListView): context["nr_funders_wo_organization"] = Funder.objects.filter( organization=None ).count() - context["pubyears"] = range(int(timezone.now().strftime("%Y")), 2015, -1) context["countrycodes"] = [ code["country"] for code in list( @@ -187,7 +186,6 @@ class OrganizationDetailView(DetailView): def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) - context["pubyears"] = range(int(timezone.now().strftime("%Y")), 2015, -1) context["balance"] = self.object.cf_balance_info return context