From 9fac27d069a85f2dd786b497c0b8b3a4e690028b Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Sun, 30 Jun 2019 17:19:54 +0200
Subject: [PATCH] Make PubFractions visible; add link to business model in
 navbar

---
 finances/templates/finances/business_model.html    |  2 +-
 finances/templates/finances/finances.html          |  4 ++++
 organizations/models.py                            | 14 +++++++++++---
 .../organizations/_organization_card.html          |  7 +++----
 organizations/templatetags/organizations_extras.py | 14 +++++++++++++-
 scipost/templates/scipost/navbar.html              |  5 +++++
 sponsors/templates/sponsors/sponsors.html          |  2 +-
 7 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/finances/templates/finances/business_model.html b/finances/templates/finances/business_model.html
index 074f9731d..34ceea755 100644
--- a/finances/templates/finances/business_model.html
+++ b/finances/templates/finances/business_model.html
@@ -202,7 +202,7 @@
 	    </p>
 	    <p>
 	      This information is prefilled by our editorial administration
-	      at the moment of publication based on a reasonable guess,
+	      at the moment of publication based on a reasonable estimate,
 	      which the authors are then asked to correct/complement/confirm
 	      (see image).
 	      These pubfractions are then automatically compiled and linked to the relevant
diff --git a/finances/templates/finances/finances.html b/finances/templates/finances/finances.html
index fdb570bb1..c8e424bf6 100644
--- a/finances/templates/finances/finances.html
+++ b/finances/templates/finances/finances.html
@@ -15,6 +15,10 @@
     <div class="col-12">
       <h2>Finances</h2>
 
+      <h3 class="highlight">Business Model</h3>
+      <p>Visit our <a href="{% url 'finances:business_model' %}">business model page</a>
+	to get a quick run-down on how we make our operations sustainable.</p>
+
       <h3 class="highlight">Sponsors</h3>
       <p>Visit our <a href="{% url 'sponsors:sponsors' %}">Sponsors page</a> to view our list of sponsors and more information on our sponsorship scheme.</p>
 
diff --git a/organizations/models.py b/organizations/models.py
index 53d896ebf..376bf3fe8 100644
--- a/organizations/models.py
+++ b/organizations/models.py
@@ -138,10 +138,18 @@ class Organization(models.Model):
         """
         Returns the sum of pubfractions for the given year.
         """
-        return OrgPubFraction.objects.filter(
+        fractions = OrgPubFraction.objects.filter(
             organization=self,
-            publication__publication_date__year=year
-        ).aggregate(Sum('fraction'))['fraction__sum']
+            publication__publication_date__year=year)
+        return {
+            'confirmed': fractions.filter(
+                publication__pubfractions_confirmed_by_authors=True
+            ).aggregate(Sum('fraction'))['fraction__sum'],
+            'estimated': fractions.filter(
+                publication__pubfractions_confirmed_by_authors=False
+            ).aggregate(Sum('fraction'))['fraction__sum'],
+            'total': fractions.aggregate(Sum('fraction'))['fraction__sum']
+        }
 
     def get_author_profiles(self):
         """
diff --git a/organizations/templates/organizations/_organization_card.html b/organizations/templates/organizations/_organization_card.html
index 7ab832722..0a85b44ff 100644
--- a/organizations/templates/organizations/_organization_card.html
+++ b/organizations/templates/organizations/_organization_card.html
@@ -76,11 +76,10 @@
 	</div>
 
 	<div class="tab-pane show active pt-4" id="publications-{{ org.id }}" role="tabpanel" aria-labelledby="publications-{{ org.id }}-tab">
-	  <h3>Publications associated to this Organization{% if perms.scipost.can_manage_organizations or "can_view_org_contacts" in user_org_perms %}
-	    <span class="text-muted small">(with total PubFractions <i class="fa fa-info-circle" data-toggle="tooltip" data-html="true" title="" data-original-title="Fraction of a publication's funding/institutional support associated to a given Organization"></i>)</span>{% endif %}:</h3>
+	  <h3>Publications associated to this Organization
+	    <span class="text-muted small">(with PubFractions <i class="fa fa-info-circle" data-toggle="tooltip" data-html="true" title="" data-original-title="Fraction of a publication's funding/institutional support associated to a given Organization"></i>)</span>:</h3>
 	  {% for pubyear in pubyears %}
-	    <h4>{{ pubyear }}{% if perms.scipost.can_manage_organizations or "can_view_org_contacts" in user_org_perms %}
-	      <span class="text-muted small">(total pubfractions: {{ org|pubfractions_in_year:pubyear }})</span>{% endif %}</h4>
+	    <h4>{{ pubyear }} <span class="text-muted small">(PubFractions {{ org|pubfractions_in_year:pubyear }})</span></h4>
 	    <ul>
 	      {% for publication in org.get_publications %}
 		{% if publication.publication_date|date:'Y'|add:"0" == pubyear %}
diff --git a/organizations/templatetags/organizations_extras.py b/organizations/templatetags/organizations_extras.py
index da588190d..cef54b010 100644
--- a/organizations/templatetags/organizations_extras.py
+++ b/organizations/templatetags/organizations_extras.py
@@ -13,4 +13,16 @@ def pubfraction_for_publication(org, publication):
 
 @register.filter(name='pubfractions_in_year')
 def pubfractions_in_year(org, year):
-    return org.pubfractions_in_year(int(year))
+    fractions = org.pubfractions_in_year(int(year))
+    if not fractions['total']:
+        return "total: 0"
+    text = "total: %s" % fractions['total']
+    if fractions['confirmed'] == fractions['total']:
+        text += " (confirmed)"
+        return text
+    elif fractions['estimated'] == fractions['total']:
+        text += " (estimated)"
+        return text
+    text += " (confirmed: %s; estimated: %s)" % (
+        fractions['confirmed'], fractions['estimated'])
+    return text
diff --git a/scipost/templates/scipost/navbar.html b/scipost/templates/scipost/navbar.html
index a53fc2ac9..e8441ac20 100644
--- a/scipost/templates/scipost/navbar.html
+++ b/scipost/templates/scipost/navbar.html
@@ -156,6 +156,11 @@
 
             <div class="dropdown-divider"></div>
 
+            <div class="dropdown-item">
+              <a href="{% url 'finances:business_model' %}">Our Business Model</a>
+              &nbsp;<i class="fa fa-angle-right" aria-hidden="true"></i>
+            </div>
+
             <div class="dropdown-item">
               <a href="{% url 'organizations:organizations' %}">Organizations<br/><span class="small">benefitting from our activities</span></a>
               &nbsp;<i class="fa fa-angle-right" aria-hidden="true"></i>
diff --git a/sponsors/templates/sponsors/sponsors.html b/sponsors/templates/sponsors/sponsors.html
index c8173bfb6..b448b8e44 100644
--- a/sponsors/templates/sponsors/sponsors.html
+++ b/sponsors/templates/sponsors/sponsors.html
@@ -72,7 +72,7 @@
 
   <div class="row">
     <div class="col-12">
-      <h3>In a nutshell, for the business savvy: support our model to reduce your costs</h3>
+      <h3>We aim to establish a healthier <a href="{% url 'finances:business_model' %}" target="_blank">business model</a> for scientific publishing</h3>
       <p>We are able to run a fully sustainable infrastructure at an estimated cost of under &euro;400 per publication, much below the current norm for APCs. The more scientists shift their publishing to SciPost, the fewer subscription/article processing charges you will have to pay as an organization. Your sponsorship will help us scale up and make our initiative sustainable.</p>
     </div>
   </div>
-- 
GitLab