From ad1252eabf6a494f6d4c7c2b1aa461afd76b7eaf Mon Sep 17 00:00:00 2001 From: koksnuss Date: Fri, 1 May 2020 23:17:37 +0200 Subject: [PATCH] solve todo --- coinmanager/coinc/urls.py | 2 +- coinmanager/coinc/views.py | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/coinmanager/coinc/urls.py b/coinmanager/coinc/urls.py index 63c7c22..4566de2 100644 --- a/coinmanager/coinc/urls.py +++ b/coinmanager/coinc/urls.py @@ -27,6 +27,6 @@ app_name = 'coinc' urlpatterns = [ path('', views.index, name='index'), path('statistik', views.statistic, name='statistic'), - path('', views.detail_country, name='country'), + path('', views.detail_country, name='country'), path('add/user//color/', views.add_user, name='add_user') ] diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py index e481b6c..ad987c8 100644 --- a/coinmanager/coinc/views.py +++ b/coinmanager/coinc/views.py @@ -17,8 +17,8 @@ # along with this program. If not, see . -from json import dumps from datetime import datetime +from json import dumps from django.http import HttpResponse from django.template import loader @@ -41,14 +41,21 @@ def index(request): return HttpResponse(template.render(context, request)) -def detail_country(request, country): +def detail_country(request, name_iso): + ''' wrapper_view for a *single* country ''' + template = loader.get_template('coinc/country.html') - c = Country.objects.get(name_iso=country) - return HttpResponse(template.render(show_country(c, single_country=True), request)) + country = Country.objects.get(name_iso=name_iso) + context = show_country(country, single_country=True) + + return HttpResponse(template.render(context, request)) @register.inclusion_tag('coinc/country.html') def show_country(country, single_country=False): + ''' detail_view for a country ''' + + # TODO why c instead country? c = { 'name_iso': country.name_iso, 'name': country.name, @@ -86,7 +93,7 @@ def show_country(country, single_country=False): for irregular_stamp, value in irregular_stamps[year].items(): stamps_per_year[irregular_stamp] = {} - # TODO this is not really a fix... + # TODO this is not a fix, when more stamps with uniqe years get added elif country.name_iso == 'gr': stamps_per_year = {'': {}} @@ -105,9 +112,10 @@ def show_country(country, single_country=False): } - @register.inclusion_tag('coinc/year.html') def show_year(country, year): + ''' show a year ''' + return { 'year': country['years'][year], 'year_short': year, @@ -116,15 +124,16 @@ def show_year(country, year): } - @register.inclusion_tag('coinc/coin.html') def show_coin(country, year, stamp, value): - ''' @param country: Country.name_iso + ''' show a coin + @param country: Country.name_iso @param year: int YYYY @param stamp: stamp_id @param value: int e [1,2,5,10,20,50,100,200,201,202,203] ''' - # TODO: fix this before the end of 2098 + + # TODO fix this before the end of 2098 year = int(year) if year == 99: year += 1900 @@ -166,6 +175,7 @@ def show_coin(country, year, stamp, value): def add_user(request, username, color): ''' add a user ''' + status = 0 message = '' @@ -182,9 +192,12 @@ def add_user(request, username, color): status = 1 message = 'Du musst einen Namen und Farbe angeben.' + # TODO is .dumps necessary? return HttpResponse(dumps({ 'status': status, 'message': message })) # TODO def statistic(request): + ''' show statistics ''' + return HttpResponse('Statistik')