diff --git a/scipost_django/scipost/templates/scipost/portal/_home_donate_prompt.html b/scipost_django/scipost/templates/scipost/portal/_home_donate_prompt.html index 0effdb68822ade9cd8abab7fa24b13b14bcd3f22..ef9887501392b699f15cb2920af669c620378582 100644 --- a/scipost_django/scipost/templates/scipost/portal/_home_donate_prompt.html +++ b/scipost_django/scipost/templates/scipost/portal/_home_donate_prompt.html @@ -8,18 +8,120 @@ <div class="card-body"> <p> - SciPost guarantees free online access to all publications in all its Journals and does not charge any article processing fees for publishing. <a href="{% url "organizations:organizations" %}">Supporting organizations</a> provide <a href="{% url "finances:subsidies" %}">operating funds</a> to SciPost through a cost-slashing consortial model. + SciPost guarantees free online access to all publications in all its Journals and does not charge any article processing fees for publishing. <a href="{% url "organizations:organizations" %}">Supporting organizations</a> provide <a href="{% url 'finances:subsidies' %}">operating funds</a> to SciPost through a cost-slashing consortial model. </p> + + <h4>Scientists, please help us out!</h4> + <p class="mb-0"> - Scientists, please help us out: if it is not listed on our organization page, please encourage your institution (through a librarian, Open Access officer, director, ...) to join by personally emailing them directly. + For each of your affiliated institutions, please encourage them to support us at an appropriate level by personally emailing them directly (through a librarian, Open Access officer, director, etc.). </p> <div class="d-flex flex-column gap-2 my-3"> - <a href="mailto:?subject=Petition to support SciPost&body={% autoescape on %}{% include 'petitions/petition_email.html' %}{% endautoescape %}&cc=sponsors@scipost.org" - class="btn bg-primary text-white">Contact your institution - <span class="ms-2">{% include "bi/envelope-fill.html" %}</span> - </a> + {% for organization in currently_affiliated_orgs %} + + <!-- Disabled for now, we don't have enough up-to-date information to display this confidently + <details class="bg-light" open> + <summary class="list-triangle bg-warning bg-opacity-10 p-2"> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}"><strong>{{ organization.name }}</strong></a> was a sponsor of SciPost, but is no longer. + <span class="text-warning float-end"> + {% include "bi/exclamation-circle-fill.html" %} + </span> + </summary> + <div class="p-2"> + <p> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}">{{ organization.name }}</a> used to be a sponsor of SciPost, but <strong>has since stopped supporting us</strong>. Its support is still necessary to sustain SciPost's activities. Please encourage them to resume their support. + </p> + <a href="mailto:?subject=Petition to support SciPost&body={% autoescape on %}{% include 'petitions/petition_email.html' %}{% endautoescape %}&cc=sponsors@scipost.org" class="w-100 btn bg-primary text-white">Contact {{ organization.name }} + <span class="ms-2">{% include "bi/envelope-fill.html" %}</span> + </a> + </div> + </details> + --> + + {% if organization.has_any_subsidy or organization.has_contributing_parent %} + + {% if organization.impact_on_reserves >= 0 %} + <details class="bg-light"> + <summary class="list-triangle bg-success bg-opacity-10 p-2"> + <span class="text-success float-end">{% include "bi/check-circle-fill.html" %}</span> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}"><strong>{{ organization.name }}</strong></a> is already a generous sponsor of SciPost. + </summary> + <p class="mb-0 p-2"> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}">{{ organization.name }}</a> is already a generous sponsor of SciPost, fully covering the costs of publishing for its affiliated authors. Thank you for your support! + </p> + </details> + {% else %} + <details class="bg-light" open> + <summary class="list-triangle bg-primary bg-opacity-10 p-2"> + <span class="text-primary float-end"> + {% include "bi/exclamation-circle-fill.html" %} + </span> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}"><strong>{{ organization.name }}</strong></a> is already a sponsor of SciPost. + </summary> + <div class="p-2"> + <p> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}">{{ organization.name }}</a> is already a sponsor of SciPost. However, <strong>its level of contribution is not sufficient</strong> to cover the costs of publishing for its affiliated authors. Please encourage them to increase their support and help sustain SciPost's activities. + </p> + <a href="mailto:?subject=Petition to support SciPost&body={% autoescape on %}{% include 'petitions/petition_email.html' %}{% endautoescape %}&cc=sponsors@scipost.org" + class="w-100 btn bg-primary text-white">Contact {{ organization.name }} + <span class="ms-2">{% include "bi/envelope-fill.html" %}</span> + </a> + </div> + </details> + {% endif %} + + {% else %} + + <details class="bg-light p-0" open> + <summary class="list-triangle bg-danger bg-opacity-10 p-2"> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}"><strong>{{ organization.name }}</strong></a> does not support SciPost. + <span class="text-danger float-end"> + {% include "bi/exclamation-circle-fill.html" %} + </span> + </summary> + <div class="p-2"> + <p> + <a href="{% url 'organizations:organization_detail' pk=organization.id %}">{{ organization.name }}</a> <strong>does not support SciPost</strong>. Its support is necessary to sustain SciPost's activities. Please encourage them to support us. + </p> + <a href="mailto:?subject=Petition to support SciPost&body={% autoescape on %}{% include 'petitions/petition_email.html' %}{% endautoescape %}&cc=sponsors@scipost.org" + class="w-100 btn bg-primary text-white">Contact {{ organization.name }} + <span class="ms-2">{% include "bi/envelope-fill.html" %}</span> + </a> + </div> + </details> + + {% endif %} + + {% if forloop.last %} + <details class="bg-light"> + <summary class="list-triangle p-2"> + Affiliated to an institution not in this list? + <span class="text-primary float-end"> + {% include "bi/question-circle-fill.html" %} + </span> + </summary> + <div class="p-2"> + <p> + If you are affiliated with an organization that is not listed here, please check our <a href="{% url 'organizations:organizations' %}">full list of affiliated organizations</a> and encourage them to support us if they are not already doing so. + </p> + <a href="mailto:?subject=Petition to support SciPost&body={% autoescape on %}{% include 'petitions/petition_email.html' %}{% endautoescape %}&cc=sponsors@scipost.org" + class="w-100 btn bg-primary text-white">Contact your institution + <span class="ms-2">{% include "bi/envelope-fill.html" %}</span> + </a> + </div> + </details> + {% endif %} + + {% empty %} + + <a href="mailto:?subject=Petition to support SciPost&body={% autoescape on %}{% include 'petitions/petition_email.html' %}{% endautoescape %}&cc=sponsors@scipost.org" + class="w-100 btn bg-primary text-white">Contact your institution + <span class="ms-2">{% include "bi/envelope-fill.html" %}</span> + </a> + + {% endfor %} </div> diff --git a/scipost_django/scipost/views.py b/scipost_django/scipost/views.py index 00410a85be028832dfb74e0635fcefdea49b9969..662f03d8be1eda0cdea25693a4db3443e38f00df 100644 --- a/scipost_django/scipost/views.py +++ b/scipost_django/scipost/views.py @@ -4,6 +4,7 @@ __license__ = "AGPL v3" import urllib +from django.db.models.functions import Cast, Coalesce from django.template.response import TemplateResponse from django.utils import timezone from django.shortcuts import get_object_or_404, render @@ -29,11 +30,13 @@ from django.core.paginator import Paginator from django.urls import reverse, reverse_lazy from django.db import transaction from django.db.models import ( + F, Q, Case, CharField, Count, Exists, + IntegerField, OuterRef, Subquery, Value, @@ -217,9 +220,44 @@ def portal_hx_home(request): else: news_items = NewsItem.objects.none() latest_blogpost = BlogPost.objects.published().first() + + if request.user.is_authenticated: + currently_affiliated_orgs = ( + Organization.objects.filter( + id__in=request.user.contributor.profile.affiliations.all() + .current() + .values("organization") + ) + # .annot_has_current_subsidy() + .annot_has_any_subsidy().annotate( + has_contributing_parent=Exists( + Organization.objects.filter( + children=OuterRef("pk"), + subsidy__isnull=False, + ) + ), + impact_on_reserves=Coalesce( + Cast( + F( + "parent__cf_balance_info__cumulative__impact_on_reserves", + ), + IntegerField(), + ), + 0, + ) + + Cast( + F("cf_balance_info__cumulative__impact_on_reserves"), + IntegerField(), + ), + ) + ) + else: + currently_affiliated_orgs = Organization.objects.none() + context = { "news_items": news_items, "latest_blogpost": latest_blogpost, + "currently_affiliated_orgs": currently_affiliated_orgs, } return render(request, "scipost/portal/_hx_home.html", context)