formatting

This commit is contained in:
moritz münch 2020-12-20 01:44:05 +01:00
parent aa20dc8534
commit 2ca47411ef

View File

@ -24,25 +24,39 @@ from django.conf import settings
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.template import loader from django.template import loader
from django.template.defaultfilters import register from django.template.defaultfilters import register
from django.views.decorators.cache import cache_page
from django.views.decorators.http import condition from django.views.decorators.http import condition
from .models import Country, Stamp, Coin, User from .models import Country, Stamp, Coin, User
def total_coin_sum(): def total_coin_sum():
''' add each coin_sum from each country and return the result
>>> total_coin_sum()
173.57
'''
total_coin_sum = 0 total_coin_sum = 0
for country in Country.objects.order_by('name'): for country in Country.objects.order_by('name'):
total_coin_sum += coin_sum_of_(country) total_coin_sum += coin_sum_of_(country)
return total_coin_sum return total_coin_sum
def coin_sum_of_(country): def coin_sum_of_(country):
''' calculate the sum of all coins from a country
>>> coin_sum_of_(germany)
346.82
'''
coin_count = {'total': 0} coin_count = {'total': 0}
for value in [1, 2, 5, 10, 20, 50, 100, 200, 201, 202, 203]: for value in [1, 2, 5, 10, 20, 50, 100, 200, 201, 202, 203]:
coin_count[value] = Coin.objects.filter( coin_count[value] = Coin.objects.filter(
country=country, country=country,
value=value value=value
).exclude(found_by__isnull=True).count() ).exclude(found_by__isnull=True).count()
if value > 200: if value > 200:
coin_count['total'] += 200 * coin_count[value] coin_count['total'] += 200 * coin_count[value]
else: else: