From 2ca47411ef22d7b7a941cde71346ddcd4ae89d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?moritz=20m=C3=BCnch?= Date: Sun, 20 Dec 2020 01:44:05 +0100 Subject: [PATCH] formatting --- coinmanager/coinc/views.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py index 1311076..52d28e2 100644 --- a/coinmanager/coinc/views.py +++ b/coinmanager/coinc/views.py @@ -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: