From e677b7fbef019433fb12068510c0138e6c5ea0f5 Mon Sep 17 00:00:00 2001 From: "J.-S. Caux" <J.S.Caux@uva.nl> Date: Fri, 12 Oct 2018 16:37:57 +0200 Subject: [PATCH] Improve sponsors --- organizations/managers.py | 15 +++++++++++++++ organizations/models.py | 2 +- sponsors/templates/sponsors/sponsors.html | 8 ++++---- sponsors/views.py | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/organizations/managers.py b/organizations/managers.py index c45a475bd..50803e139 100644 --- a/organizations/managers.py +++ b/organizations/managers.py @@ -9,7 +9,16 @@ from django.db import models class OrganizationQuerySet(models.QuerySet): + def all_sponsors(self): + """ + All Organizations which have subsidized SciPost at least once in the past. + """ + return self.filter(subsidy__amount__gte=0) + def current_sponsors(self): + """ + Organizations which have a Subsidy which is ongoing (date_until <= today). + """ return self.filter(subsidy__date_until__gte=datetime.date.today()) def with_subsidy_above_and_up_to(self, min_amount, max_amount=None): @@ -21,3 +30,9 @@ class OrganizationQuerySet(models.QuerySet): if max_amount: qs = qs.filter(max_subsidy__lt=max_amount) return qs + + def order_by_total_amount_received(self): + """ + Order by (decreasing) total amount received. + """ + return self.annotate(total=models.Sum('subsidy__amount')).order_by('-total') diff --git a/organizations/models.py b/organizations/models.py index efca90455..f47a81b12 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -154,7 +154,7 @@ class Organization(models.Model): """ return self.subsidy_set.filter(date_until__gte=datetime.date.today()).exists() - def get_total_subsidies_obtained(self, n_years_part=None): + def get_total_subsidies_obtained(self, n_years_past=None): """ Computes the total amount received by SciPost, in the form of subsidies from this Organization. diff --git a/sponsors/templates/sponsors/sponsors.html b/sponsors/templates/sponsors/sponsors.html index d45e9f02a..adb2a3589 100644 --- a/sponsors/templates/sponsors/sponsors.html +++ b/sponsors/templates/sponsors/sponsors.html @@ -90,28 +90,28 @@ <div class="col-12"> <h1 class="highlight">Our current Sponsors</h1> - <h3 class="highlight">Platinum sponsors (€20k and above):</h3> + <h3 class="highlight">€20k and above:</h3> <div class="card-columns"> {% for sponsor in sponsors_20kplus %} {% include 'sponsors/_sponsor_card.html' with sponsor=sponsor %} {% endfor %} </div> - <h3 class="highlight">Gold sponsors (€10k and above):</h3> + <h3 class="highlight">€10k and above:</h3> <div class="card-columns"> {% for sponsor in sponsors_10kplus %} {% include 'sponsors/_sponsor_card.html' with sponsor=sponsor %} {% endfor %} </div> - <h3 class="highlight">Silver sponsors (€5k and above):</h3> + <h3 class="highlight">€5k and above:</h3> <div class="card-columns"> {% for sponsor in sponsors_5kplus %} {% include 'sponsors/_sponsor_card.html' with sponsor=sponsor %} {% endfor %} </div> - <h3 class="highlight">All current Sponsors</h3> + <h3 class="highlight">Our other current Sponsors:</h3> <div class="card-columns"> {% for sponsor in current_sponsors %} {% include 'sponsors/_sponsor_card.html' with sponsor=sponsor %} diff --git a/sponsors/views.py b/sponsors/views.py index 7768f060d..1d7a6a7fa 100644 --- a/sponsors/views.py +++ b/sponsors/views.py @@ -11,11 +11,11 @@ def sponsors(request): sponsors_20kplus = Organization.objects.with_subsidy_above_and_up_to(20000) sponsors_10kplus = Organization.objects.with_subsidy_above_and_up_to(10000, 20000) sponsors_5kplus = Organization.objects.with_subsidy_above_and_up_to(5000, 10000) - current_sponsors = Organization.objects.current_sponsors() + current_sponsors = Organization.objects.current_sponsors().with_subsidy_above_and_up_to(0, 5000) context = { 'sponsors_20kplus': sponsors_20kplus, 'sponsors_10kplus': sponsors_10kplus, 'sponsors_5kplus': sponsors_5kplus, - 'current_sponsors': current_sponsors, + 'current_sponsors': current_sponsors.order_by_total_amount_received(), } return render(request, 'sponsors/sponsors.html', context) -- GitLab