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