2024-05-10 01:27:51 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
2023-10-19 22:44:24 +00:00
|
|
|
from django.shortcuts import render
|
|
|
|
|
2023-10-20 07:25:55 +00:00
|
|
|
from .. import ParameterValidator
|
2024-05-10 01:27:51 +00:00
|
|
|
from .models import Supporter
|
2016-12-02 17:50:21 +00:00
|
|
|
|
2023-10-19 22:44:24 +00:00
|
|
|
|
2024-05-10 01:27:51 +00:00
|
|
|
def sustainers(request):
|
2023-10-19 22:54:35 +00:00
|
|
|
with ParameterValidator(request.GET, 'upgrade_id') as validator:
|
2016-12-02 20:07:35 +00:00
|
|
|
try:
|
|
|
|
amount_param = float(request.GET['upgrade'])
|
|
|
|
except (KeyError, ValueError):
|
|
|
|
validator.fail()
|
|
|
|
else:
|
2016-12-02 20:15:49 +00:00
|
|
|
validator.validate('{:.2f}'.format(amount_param))
|
2016-12-02 20:07:35 +00:00
|
|
|
partial_amount = amount_param if validator.valid else 0
|
2016-12-02 17:50:21 +00:00
|
|
|
context = {
|
|
|
|
'partial_amount': partial_amount,
|
|
|
|
'minimum_amount': 120 - partial_amount,
|
|
|
|
}
|
2024-05-10 01:27:51 +00:00
|
|
|
return render(request, "supporters/sustainers.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
def sponsors(request):
|
|
|
|
"""Conservancy Sponsors Page view
|
|
|
|
|
|
|
|
Performs object queries necessary to render the sponsors page.
|
|
|
|
"""
|
|
|
|
supporters = Supporter.objects.all().filter(display_until_date__gte=datetime.now())
|
|
|
|
supporters_count = len(supporters)
|
|
|
|
anonymous_count = len(supporters.filter(display_name='Anonymous'))
|
|
|
|
supporters = supporters.exclude(display_name='Anonymous').order_by('ledger_entity_id')
|
|
|
|
c = {
|
|
|
|
'supporters' : supporters,
|
|
|
|
'supporters_count' : supporters_count,
|
|
|
|
'anonymous_count' : anonymous_count
|
|
|
|
}
|
|
|
|
return render(request, "supporters/sponsors.html", c)
|