From 13805f790dd3a37f762792db74db45ad6f95ab70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Fri, 29 Dec 2017 17:02:33 +0100 Subject: [PATCH] add tableview in /currencies --- .../didgeridoo/currencies/exchange_rates.py | 8 ++++--- .../templates/currencies/index.html | 16 ++++++++++++++ django/didgeridoo/currencies/views.py | 21 ++++++++++--------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/django/didgeridoo/currencies/exchange_rates.py b/django/didgeridoo/currencies/exchange_rates.py index db1cc6b..5415301 100644 --- a/django/didgeridoo/currencies/exchange_rates.py +++ b/django/didgeridoo/currencies/exchange_rates.py @@ -53,8 +53,10 @@ def get_exchange_rate(): datetime_str = item.find('dc:date', ns).text # convert string to date object: # https://stackoverflow.com/a/12282040/4061870 + # seams like snb striked the microsecond somewhere between Nov. and + # Dez. 2017 so maybe first check time type. "%Y-%m-%dT%H:%M:%S.%f%z" date = datetime.strptime(''.join(datetime_str.rsplit(':', 1)), - "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%Y-%m-%d") + "%Y-%m-%dT%H:%M:%S%z").strftime("%Y-%m-%d") # only the values of today are used so check for date: if date == today: title = item.find('none:title', ns).text @@ -110,11 +112,11 @@ def get_exchange_rate(): # CHFvalue, "CHF and 1 ", base_currency, " costs: ", # FOREIGNvalue_round, target_currency) exchange_rates.update( - {target_currency: FOREIGNvalue_round, "date": date}) + {target_currency: FOREIGNvalue_round}) # Print the Dictionary: # print(exchange_rates) else: break - return(exchange_rates) + return(exchange_rates, date) # for development its preferable to see that the for loop is done: # print('no more fresh data!') diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index 50d944a..8e67685 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -6,6 +6,22 @@

Currencies in CHF

{% if currency_list %} + + + + {% for currency in currency_list %} + + {% endfor %} + + + + {% for currency in currency_list %} + + {% endfor %} + +
DATE{{ currency.name }}
{{ date }}{{ currency.exchange_rate_to_chf }}
+
+