From 19afc446ed3ae448882d50a34a166e14e131432b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Fri, 29 Dec 2017 19:26:01 +0100 Subject: [PATCH] changed view and deleted the database unique filed --- .../didgeridoo/currencies/exchange_rates.py | 8 +++++--- .../migrations/0004_auto_20171229_1708.py | 20 +++++++++++++++++++ .../migrations/0005_auto_20171229_1735.py | 20 +++++++++++++++++++ .../migrations/0006_auto_20171229_1747.py | 20 +++++++++++++++++++ .../migrations/0007_auto_20171229_1806.py | 20 +++++++++++++++++++ django/didgeridoo/currencies/models.py | 2 +- .../templates/currencies/index.html | 13 ++++++------ django/didgeridoo/currencies/views.py | 14 ++++++------- 8 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 django/didgeridoo/currencies/migrations/0004_auto_20171229_1708.py create mode 100644 django/didgeridoo/currencies/migrations/0005_auto_20171229_1735.py create mode 100644 django/didgeridoo/currencies/migrations/0006_auto_20171229_1747.py create mode 100644 django/didgeridoo/currencies/migrations/0007_auto_20171229_1806.py diff --git a/django/didgeridoo/currencies/exchange_rates.py b/django/didgeridoo/currencies/exchange_rates.py index 5415301..bb12c47 100644 --- a/django/didgeridoo/currencies/exchange_rates.py +++ b/django/didgeridoo/currencies/exchange_rates.py @@ -55,9 +55,11 @@ def get_exchange_rate(): # 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%z").strftime("%Y-%m-%d") - # only the values of today are used so check for date: + date = datetime.strptime(''.join( + datetime_str.rsplit(':', 1)), + "%Y-%m-%dT%H:%M:%S%z").strftime( + "%Y-%m-%d") + # only the values of today are used so check for date in XML: if date == today: title = item.find('none:title', ns).text base_currency = item.find(rate_path + diff --git a/django/didgeridoo/currencies/migrations/0004_auto_20171229_1708.py b/django/didgeridoo/currencies/migrations/0004_auto_20171229_1708.py new file mode 100644 index 0000000..ad84626 --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0004_auto_20171229_1708.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-12-29 16:08 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0003_auto_20171227_1119'), + ] + + operations = [ + migrations.AlterField( + model_name='exchangerate', + name='name', + field=models.CharField(max_length=200), + ), + ] diff --git a/django/didgeridoo/currencies/migrations/0005_auto_20171229_1735.py b/django/didgeridoo/currencies/migrations/0005_auto_20171229_1735.py new file mode 100644 index 0000000..3ac6227 --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0005_auto_20171229_1735.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-12-29 16:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0004_auto_20171229_1708'), + ] + + operations = [ + migrations.AlterField( + model_name='exchangerate', + name='date', + field=models.DateField(null=True, verbose_name='%Y-%m-%dT%H:%M:%S'), + ), + ] diff --git a/django/didgeridoo/currencies/migrations/0006_auto_20171229_1747.py b/django/didgeridoo/currencies/migrations/0006_auto_20171229_1747.py new file mode 100644 index 0000000..a2a330b --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0006_auto_20171229_1747.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-12-29 16:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0005_auto_20171229_1735'), + ] + + operations = [ + migrations.AlterField( + model_name='exchangerate', + name='date', + field=models.DateTimeField(null=True, verbose_name='%Y-%m-%dT%H:%M:%S'), + ), + ] diff --git a/django/didgeridoo/currencies/migrations/0007_auto_20171229_1806.py b/django/didgeridoo/currencies/migrations/0007_auto_20171229_1806.py new file mode 100644 index 0000000..2455467 --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0007_auto_20171229_1806.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-12-29 17:06 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0006_auto_20171229_1747'), + ] + + operations = [ + migrations.AlterField( + model_name='exchangerate', + name='date', + field=models.DateField(null=True, verbose_name='%Y-%m-%d'), + ), + ] diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py index fb6d10c..ca6ed15 100644 --- a/django/didgeridoo/currencies/models.py +++ b/django/didgeridoo/currencies/models.py @@ -2,7 +2,7 @@ from django.db import models class ExchangeRate(models.Model): - name = models.CharField(max_length=200, unique=True) + name = models.CharField(max_length=200) date = models.DateField('%Y-%m-%d', null=True) exchange_rate_to_chf = models.FloatField(max_length=5) diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index 8e67685..bddcee2 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -13,14 +13,15 @@ {{ currency.name }} {% endfor %} - - {{ date }} - {% for currency in currency_list %} - {{ currency.exchange_rate_to_chf }} - {% endfor %} - + + {{ date }} + {% for currency in currency_list %} + {{ currency.exchange_rate_to_chf }} + {% endfor %} +
+

{{ message }}