From 6bee5e29ae7b8dde93058e8de31ed47dc29d994f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jean-S=C3=A9bastien=20Caux?= <git@jscaux.org>
Date: Sun, 24 Mar 2024 13:12:27 +0100
Subject: [PATCH] Add ordering by impact on reserves (for FinAdmin) in org list

---
 .../organizations/organization_list.html          | 15 +++++++++++++--
 scipost_django/organizations/views.py             |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/scipost_django/organizations/templates/organizations/organization_list.html b/scipost_django/organizations/templates/organizations/organization_list.html
index dffb9ebb3..8b80096df 100644
--- a/scipost_django/organizations/templates/organizations/organization_list.html
+++ b/scipost_django/organizations/templates/organizations/organization_list.html
@@ -110,7 +110,7 @@
 	  <tr>
 	    <th><a href="{% add_get_parameters order_by='country' %}">Country</a></th>
 	    <th><a href="{% add_get_parameters order_by='name' %}">Name</a>&nbsp;&nbsp;<small>[acronym]</small></th>
-	    <th>NAP <span data-bs-toggle="tooltip" data-bs-html="true" title="" data-original-title="Number of associated publications<br/>For details, click on the Organization and consult the Associated Publications tab">{% include 'bi/info-circle-fill.html' %}</span>
+	    <th>NAP <span data-bs-toggle="tooltip" data-bs-html="true" title="" data-original-title="Number of associated publications<br/>For details, click on the Organization and consult the Associated Publications tab">{% include 'bi/info-circle-fill.html' %}</span><br>
 	      {% if request.GET.ordering != 'asc' %}
 		<a href="{% add_get_parameters order_by='nap' ordering='asc' %}">{% include 'bi/sort-up.html' %}</a>
 	      {% else %}
@@ -124,7 +124,18 @@
 	    </th>
 	    <th>SciPost sponsor?</th>
 	    {% if 'finadmin' in user_roles %}
-	      <th class="border border-danger bg-danger bg-opacity-10"><span class="text-danger">FinAdmin</span><br>Impact&nbsp;on<br>reserves</th>
+	      <th class="border border-danger bg-danger bg-opacity-10"><span class="text-danger">FinAdmin</span><br>Impact&nbsp;on<br>reserves<br>
+		{% if request.GET.ordering != 'asc' %}
+		  <a href="{% add_get_parameters order_by='impact' ordering='asc' %}">{% include 'bi/sort-up.html' %}</a>
+		{% else %}
+		  <a href="{% url 'organizations:organizations' %}">{% include 'bi/sort-up.html' %}</a>
+		{% endif %}
+		{% if request.GET.ordering != 'desc' %}
+		  <a href="{% add_get_parameters order_by='impact' ordering='desc' %}">{% include 'bi/sort-down.html' %}</a>
+		{% else %}
+		  <a href="{% url 'organizations:organizations' %}">{% include 'bi/sort-down.html' %}</a>
+		{% endif %}
+	      </th>
 	    {% endif %}
 	  </tr>
 	</thead>
diff --git a/scipost_django/organizations/views.py b/scipost_django/organizations/views.py
index 53907dec9..ca15061a7 100644
--- a/scipost_django/organizations/views.py
+++ b/scipost_django/organizations/views.py
@@ -166,6 +166,8 @@ class OrganizationListView(PaginationMixin, ListView):
             qs = qs.exclude(cf_nr_associated_publications__isnull=True).order_by(
                 "cf_nr_associated_publications"
             )
+        elif order_by == "impact":
+            qs = qs.order_by("cf_balance_info__cumulative__impact_on_reserves")
         if ordering == "desc":
             qs = qs.reverse()
         return qs.prefetch_related("logos")
-- 
GitLab