solve todo

This commit is contained in:
koksnuss 2020-05-01 23:17:37 +02:00
parent 6240586d25
commit ad1252eabf
2 changed files with 23 additions and 10 deletions

View File

@ -27,6 +27,6 @@ app_name = 'coinc'
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('statistik', views.statistic, name='statistic'), path('statistik', views.statistic, name='statistic'),
path('<str:country>', views.detail_country, name='country'), path('<str:name_iso>', views.detail_country, name='country'),
path('add/user/<str:username>/color/<str:color>', views.add_user, name='add_user') path('add/user/<str:username>/color/<str:color>', views.add_user, name='add_user')
] ]

View File

@ -17,8 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from json import dumps
from datetime import datetime from datetime import datetime
from json import dumps
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
@ -41,14 +41,21 @@ def index(request):
return HttpResponse(template.render(context, 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') template = loader.get_template('coinc/country.html')
c = Country.objects.get(name_iso=country) country = Country.objects.get(name_iso=name_iso)
return HttpResponse(template.render(show_country(c, single_country=True), request)) context = show_country(country, single_country=True)
return HttpResponse(template.render(context, request))
@register.inclusion_tag('coinc/country.html') @register.inclusion_tag('coinc/country.html')
def show_country(country, single_country=False): def show_country(country, single_country=False):
''' detail_view for a country '''
# TODO why c instead country?
c = { c = {
'name_iso': country.name_iso, 'name_iso': country.name_iso,
'name': country.name, 'name': country.name,
@ -86,7 +93,7 @@ def show_country(country, single_country=False):
for irregular_stamp, value in irregular_stamps[year].items(): for irregular_stamp, value in irregular_stamps[year].items():
stamps_per_year[irregular_stamp] = {} 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': elif country.name_iso == 'gr':
stamps_per_year = {'': {}} stamps_per_year = {'': {}}
@ -105,9 +112,10 @@ def show_country(country, single_country=False):
} }
@register.inclusion_tag('coinc/year.html') @register.inclusion_tag('coinc/year.html')
def show_year(country, year): def show_year(country, year):
''' show a year '''
return { return {
'year': country['years'][year], 'year': country['years'][year],
'year_short': year, 'year_short': year,
@ -116,15 +124,16 @@ def show_year(country, year):
} }
@register.inclusion_tag('coinc/coin.html') @register.inclusion_tag('coinc/coin.html')
def show_coin(country, year, stamp, value): 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 year: int YYYY
@param stamp: stamp_id @param stamp: stamp_id
@param value: int e [1,2,5,10,20,50,100,200,201,202,203] @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) year = int(year)
if year == 99: if year == 99:
year += 1900 year += 1900
@ -166,6 +175,7 @@ def show_coin(country, year, stamp, value):
def add_user(request, username, color): def add_user(request, username, color):
''' add a user ''' ''' add a user '''
status = 0 status = 0
message = '' message = ''
@ -182,9 +192,12 @@ def add_user(request, username, color):
status = 1 status = 1
message = 'Du musst einen Namen und Farbe angeben.' message = 'Du musst einen Namen und Farbe angeben.'
# TODO is .dumps necessary?
return HttpResponse(dumps({ 'status': status, 'message': message })) return HttpResponse(dumps({ 'status': status, 'message': message }))
# TODO # TODO
def statistic(request): def statistic(request):
''' show statistics '''
return HttpResponse('Statistik') return HttpResponse('Statistik')