website/www/conservancy/apps/supporter/views.py
Ben Sturmfels b7e2ce2a4d
Switch to relative imports
The relative imports make it clearer what code is within the project and where
it's coming from.
2023-10-20 09:45:53 +11:00

19 lines
605 B
Python

from django.shortcuts import render
import conservancy
def index(request):
with conservancy.ParameterValidator(request.GET, 'upgrade_id') as validator:
try:
amount_param = float(request.GET['upgrade'])
except (KeyError, ValueError):
validator.fail()
else:
validator.validate('{:.2f}'.format(amount_param))
partial_amount = amount_param if validator.valid else 0
context = {
'partial_amount': partial_amount,
'minimum_amount': 120 - partial_amount,
}
return render(request, "supporter/index.html", context)