diff --git a/coinmanager/coinc/templates/coinc/year.html b/coinmanager/coinc/templates/coinc/year.html index 19310b1..b6542e0 100644 --- a/coinmanager/coinc/templates/coinc/year.html +++ b/coinmanager/coinc/templates/coinc/year.html @@ -1,6 +1,16 @@ -{% for stamp in year %} -
{{ stamp }}{{ year_short }}
-{% for value in values %}{% show_coin country year_short stamp value %}{% endfor %} {% endfor %}{% ifnotequal year|length 1 %} - - - {% endifnotequal %} +{% for stamp, coins in stamps.items %} + + +
{{ stamp }}{{ year_short }}
+ + {% for value, coin in coins.items %} + {% show_coin coin value %} + {% endfor %} + +{% endfor %} + +{% ifnotequal stamps|length 1 %} + + + +{% endifnotequal %} diff --git a/coinmanager/coinc/views.py b/coinmanager/coinc/views.py index 1b027fe..1e6ef12 100644 --- a/coinmanager/coinc/views.py +++ b/coinmanager/coinc/views.py @@ -90,6 +90,7 @@ def show_country(country, single_country=False): 'comment': country.comment, 'years': {} } + coin_sum = coin_sum_of_(country) irregular_stamps = {} stamps = Stamp.objects.filter(country=country.name_iso).values( @@ -125,15 +126,79 @@ def show_country(country, single_country=False): elif country.name_iso == 'gr': stamps_per_year = {'': {}} - year_short = year[2:4] - c['years'][year_short] = {} + c['years'][year] = {} for stamp in stamps_per_year: - c['years'][year_short][stamp] = {'name': stamp} + c['years'][year][stamp] = { + 1: {}, + 2: {}, + 5: {}, + 10: {}, + 20: {}, + 50: {}, + 100: {}, + 200: {}, + 201: {}, + 202: {}, + 203: {} + } stamps_per_year = {} - coin_sum = coin_sum_of_(country) + coins = Coin.objects.all().filter(country=country) + for coin in coins: + + td_class = '' + if not coin.exists: + td_class = 'noexist' + elif coin.buy_only: + td_class = 'buy_only' + elif coin.circulation and coin.circulation <= 1500000: + td_class = 'rare' + elif coin.value in [10, 20, 50]: + td_class = 'brass' + elif coin.found_by: + td_class = 'found' + else: + td_class = 'exist' + + if coin.in_collector: + td_class += ' ec' + elif coin.checked: + td_class += ' checked' + + div_class = '' + marker = '' + if coin.found_by: + div_class = f"found {coin.found_by}" + marker = '✔' + + name = coin.name if coin.name else '' + special_class = '' + special_name = '' + if name: + if coin.value == 201: + special_name = 'special1_name' + elif coin.value == 202: + special_name = 'special2_name' + elif coin.value == 203: + special_name = 'special3_name' + + if len(name) >= 18 and len(name) <= 42: + special_class = 'two_lines' + elif len(name) > 42: + special_class = 'three_lines' + + stamp = coin.stamp.name_short if coin.stamp else '' + + c['years'][str(coin.year)][stamp][coin.value] = { + 'marker': marker, + 'name': name, + 'td_class': td_class, + 'div_class': div_class, + 'special_class': special_class, + 'special_name': special_name + } return { 'country': c, @@ -146,94 +211,27 @@ 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, - 'values': [1, 2, 5, 10, 20, 50, 100, 200, 201, 202, 203], - 'country': country['name_iso'] + 'stamps': country['years'][year], + 'year_short': year[2:4], } @register.inclusion_tag('coinc/coin.html') -def show_coin(country, year, stamp, value): - ''' 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] - ''' - year = int(year) # TODO fix this before the end of 2098 - if year == 99: - year += 1900 - else: - year += 2000 - - if stamp == "": - stamp = None - - try: - coin = Coin.objects.get(country=country, year=year, stamp=stamp, value=value) - except Coin.DoesNotExist: - return { - 'value': value - } - except Coin.MultipleObjectsReturned: +def show_coin(coin, value): + ''' show a coin ''' + if coin: return { 'value': value, - 'marker': 'Fehler!' + 'marker': coin['marker'], + 'name': coin['name'], + 'td_class': coin['td_class'], + 'div_class': coin['div_class'], + 'special_class': coin['special_class'], + 'special_name': coin['special_name'], } - - td_class = '' - if not coin.exists: - td_class = 'noexist' - elif coin.buy_only: - td_class = 'buy_only' - elif coin.circulation and coin.circulation <= 1500000: - td_class = 'rare' - elif coin.value in [10, 20, 50]: - td_class = 'brass' - elif coin.found_by: - td_class = 'found' else: - td_class = 'exist' - - if coin.in_collector: - td_class += ' ec' - elif coin.checked: - td_class += ' checked' - - div_class = '' - marker = '' - if coin.found_by: - div_class = f"found {coin.found_by}" - marker = '✔' - - name = coin.name if coin.name else '' - special_class = '' - special_name = '' - if name: - if value == 201: - special_name = 'special1_name' - elif value == 202: - special_name = 'special2_name' - elif value == 203: - special_name = 'special3_name' - - if len(name) >= 18 and len(name) <= 42: - special_class = 'two_lines' - elif len(name) > 42: - special_class = 'three_lines' - - return { - 'value': value, - 'marker': marker, - 'name': name, - 'td_class': td_class, - 'div_class': div_class, - 'special_class': special_class, - 'special_name': special_name - } + return {} def add_user(request, username, color):