From e675c02ec23991e43feb0cb744d0dddf45609760 Mon Sep 17 00:00:00 2001 From: koksnuss Date: Mon, 27 Apr 2020 01:00:03 +0200 Subject: [PATCH] make gui work again. show stamps! :)) greece still has errors --- Pipfile | 1 + coinmanager/coinc/templates/base.html | 32 ++++++++ .../coinc/templates/coinc/country.html | 6 +- coinmanager/coinc/templates/coinc/index.html | 36 +-------- coinmanager/coinc/templates/coinc/stamp.html | 2 - coinmanager/coinc/templates/coinc/year.html | 17 ++++- coinmanager/coinc/urls.py | 4 +- coinmanager/coinc/views.py | 75 +++++++++++++------ 8 files changed, 108 insertions(+), 65 deletions(-) create mode 100644 coinmanager/coinc/templates/base.html delete mode 100644 coinmanager/coinc/templates/coinc/stamp.html diff --git a/Pipfile b/Pipfile index 21bc4e8..d024be7 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,7 @@ verify_ssl = true [packages] django = "*" +pudb = "*" [requires] python_version = "3.6" diff --git a/coinmanager/coinc/templates/base.html b/coinmanager/coinc/templates/base.html new file mode 100644 index 0000000..ec98645 --- /dev/null +++ b/coinmanager/coinc/templates/base.html @@ -0,0 +1,32 @@ + + + + + + + Münzsammlung {% load static %} + + + + + {% block content %}{% endblock %} + + diff --git a/coinmanager/coinc/templates/coinc/country.html b/coinmanager/coinc/templates/coinc/country.html index 68a661b..6d0b837 100644 --- a/coinmanager/coinc/templates/coinc/country.html +++ b/coinmanager/coinc/templates/coinc/country.html @@ -9,7 +9,9 @@ x € - {% for stamp in country.stamps %} - {% show_stamp stamp %}{% endfor %} + + {% for year in country.years %} + {% show_year country year %} + {% endfor %} diff --git a/coinmanager/coinc/templates/coinc/index.html b/coinmanager/coinc/templates/coinc/index.html index 96027b9..04d2704 100644 --- a/coinmanager/coinc/templates/coinc/index.html +++ b/coinmanager/coinc/templates/coinc/index.html @@ -1,38 +1,10 @@ - - - - - - - Münzsammlung {% load static %} - - - - + {% extends "base.html" %} + {% block content %} {% if countrys %} - {% navigation countrys %} + {% show_navigation countrys %} {% for country in countrys %} {% show_country country %} {% endfor %} {% else %}

Trage zuerst Länder im Adminbereich ein.

{% endif %} - - + {% endblock %} diff --git a/coinmanager/coinc/templates/coinc/stamp.html b/coinmanager/coinc/templates/coinc/stamp.html deleted file mode 100644 index 1c40e58..0000000 --- a/coinmanager/coinc/templates/coinc/stamp.html +++ /dev/null @@ -1,2 +0,0 @@ -{% for year in country.years %} -{% show_year year %}{% endfor %} diff --git a/coinmanager/coinc/templates/coinc/year.html b/coinmanager/coinc/templates/coinc/year.html index 3c856ad..fe30b1a 100644 --- a/coinmanager/coinc/templates/coinc/year.html +++ b/coinmanager/coinc/templates/coinc/year.html @@ -1,5 +1,16 @@ + {% for stamp in year %} - -
{{ year.short }}
{% for coin in year.coins %} - {% show_coin coin %}{% endfor %} +
{{ stamp }}{{ year_int }}
+ + + + + + + + + + + + {% endfor %} diff --git a/coinmanager/coinc/urls.py b/coinmanager/coinc/urls.py index 7f7f19c..f49c441 100644 --- a/coinmanager/coinc/urls.py +++ b/coinmanager/coinc/urls.py @@ -25,7 +25,7 @@ from . import views app_name = 'coinc' urlpatterns = [ - path('', views.index, name='index'), + path('', views.IndexView.as_view(), name='index'), path('statistik', views.statistic, name='statistic'), - path('', views.country, name='country'), + path('', views.DetailView.as_view(), name='country'), ] diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py index b396b33..b666458 100644 --- a/coinmanager/coinc/views.py +++ b/coinmanager/coinc/views.py @@ -23,26 +23,30 @@ from datetime import datetime from django.http import HttpResponse from django.template import loader from django.template.defaultfilters import register +from django.views import generic -from .models import Country +from .models import Country, Stamp -def index(request): - countrys = Country.objects.order_by('name') - template = loader.get_template('coinc/index.html') - year_now = datetime.now().year - context = {'countrys': countrys} +class IndexView(generic.ListView): + template_name = 'coinc/index.html' + context_object_name = 'countrys' - return HttpResponse(template.render(context, request)) + def get_queryset(self): + ''' return all countries ordered by name ''' + return Country.objects.order_by('name_iso') -def country(request, country): - return HttpResponse(f"Land: {country}") + +class DetailView(generic.DetailView): + model = Country + template_name = 'coinc/country.html' + @register.inclusion_tag('coinc/navigation.html') -def navigation(countrys): +def show_navigation(countrys): return {'countrys': countrys} @@ -51,6 +55,12 @@ def coins(country, year): return country['years'][year] +@register.inclusion_tag('coinc/year.html') +def show_year(country, year): + return { 'year': country['years'][year], + 'year_int': year } + + @register.inclusion_tag('coinc/country.html') def show_country(country): year_now = datetime.now().year @@ -58,25 +68,42 @@ def show_country(country): 'name_iso': country.name_iso, 'name': country.name, 'comment': country.comment, - 'euro_member_since': country.euro_member_since, 'years': {} } + irregular_stamps = {} + stamps = Stamp.objects.filter(country=country.name_iso).values('name_short', 'years') + + if stamps: + temp_stamps = {} + for stamp in stamps: + stamp_name_short = stamp['name_short'] + if stamp['years'] == "": + temp_stamps[stamp_name_short] = {} + else: + for year in stamp['years'].split(","): + irregular_stamps[year] = {} + irregular_stamps[year][stamp_name_short] = {} + temp_stamps[''] = {} + stamps = temp_stamps + else: + stamps = {'': {}} + for year in range(country.euro_member_since, year_now + 1): + stamps_per_year = stamps + if irregular_stamps: + print(irregular_stamps) + if str(year) in irregular_stamps: + print(f"{year} in!") + for irregular_stamp, value in irregular_stamps[str(year)].items(): + stamps_per_year[irregular_stamp] = {} + y = str(year)[2:4] - c['years'][y] = { - '1': 'x', - '2': '', - '5': '', - '10': '', - '20': 'x', - '50': '', - '100': '', - '200': 'x', - '201': '', - '202': '', - '203': '' - } + c['years'][y] = {} + for stamp in stamps_per_year: + c['years'][y][stamp] = {'name': stamp} + if country.name_iso == 'gr' or country.name_iso == 'de': + print(c) return {'country': c}