From 66f19c436b974efb76b9484959543f7641b8b8eb Mon Sep 17 00:00:00 2001 From: koksnuss Date: Mon, 1 Jun 2020 01:12:27 +0200 Subject: [PATCH] up --- .../coinc/templates/coinc/country.html | 2 +- coinmanager/coinc/templates/coinc/index.html | 2 +- coinmanager/coinc/templates/footer.html | 1 + coinmanager/coinc/views.py | 41 ++++++++++++------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/coinmanager/coinc/templates/coinc/country.html b/coinmanager/coinc/templates/coinc/country.html index 8217fff..27992f5 100644 --- a/coinmanager/coinc/templates/coinc/country.html +++ b/coinmanager/coinc/templates/coinc/country.html @@ -10,7 +10,7 @@ {{ country.name }}{% if country.comment %} - {{ country.comment }}{% endif %} -
{{ total_coins }}
+
{{ coin_sum }}
diff --git a/coinmanager/coinc/templates/coinc/index.html b/coinmanager/coinc/templates/coinc/index.html index 23db288..d44666b 100644 --- a/coinmanager/coinc/templates/coinc/index.html +++ b/coinmanager/coinc/templates/coinc/index.html @@ -1,7 +1,7 @@ {% include 'header.html' with title='Münzsammlung' %} {% if countrys %} +

Gesamtwert {{ coin_sum }}

{% include 'coinc/filter_country.html' with countrys=countrys %} {% else %}

Trage zuerst Länder im Adminbereich ein.

{% endif %} - Version 200531 {% include 'footer.html' with title='Münzsammlung' %} diff --git a/coinmanager/coinc/templates/footer.html b/coinmanager/coinc/templates/footer.html index b605728..a61e4f4 100644 --- a/coinmanager/coinc/templates/footer.html +++ b/coinmanager/coinc/templates/footer.html @@ -1,2 +1,3 @@ + Version 200531 diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py index 7806bbd..381066c 100644 --- a/coinmanager/coinc/views.py +++ b/coinmanager/coinc/views.py @@ -27,15 +27,39 @@ from django.template.defaultfilters import register from .models import Country, Stamp, Coin, User +def total_coin_sum(): + 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): + 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() + if value > 200: + coin_count['total'] += 200 * coin_count[value] + else: + coin_count['total'] += value * coin_count[value] + coin_count['total'] /= 100 + return coin_count['total'] + + def index(request): ''' index view ''' template = loader.get_template('coinc/index.html') countrys = Country.objects.order_by('name') users = User.objects.order_by('id') + coin_sum = total_coin_sum() context = { 'countrys': countrys, - 'users': users + 'users': users, + 'coin_sum': f"{coin_sum:.2f} €" } return HttpResponse(template.render(context, request)) @@ -108,24 +132,13 @@ def show_country(country, single_country=False): stamps_per_year = {} - - 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() - if value > 200: - coin_count['total'] += 200 * coin_count[value] - else: - coin_count['total'] += value * coin_count[value] - coin_count['total'] /= 100 + coin_sum = coin_sum_of_(country) return { 'country': c, 'single_country': single_country, 'users': User.objects.order_by('id').values('name','color'), - 'total_coins': f"{coin_count['total']:.2f} €" + 'coin_sum': f"{coin_sum:.2f} €" }