diff --git a/ansible/roles/web_AI-5/tasks/setup_script.sh b/ansible/roles/web_AI-5/tasks/setup_script.sh index 6243fb4..1bcd57b 100755 --- a/ansible/roles/web_AI-5/tasks/setup_script.sh +++ b/ansible/roles/web_AI-5/tasks/setup_script.sh @@ -4,9 +4,11 @@ mysql < /vagrant/sql/01_create_database.sql #remove old migrations rm /vagrant/django/didgeridoo/webshop/migrations/*.py +rm /vagrant/django/didgeridoo/currencies/migrations/*.py #create and insert the new migrations python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop +python3 /vagrant/django/didgeridoo/manage.py makemigrations currencies python3 /vagrant/django/didgeridoo/manage.py migrate #insert some default data into the database diff --git a/django/.idea/django.iml b/django/.idea/django.iml index 6711606..0acd853 100644 --- a/django/.idea/django.iml +++ b/django/.idea/django.iml @@ -2,7 +2,7 @@ - + diff --git a/django/.idea/misc.xml b/django/.idea/misc.xml index 2c50d4f..539c015 100644 --- a/django/.idea/misc.xml +++ b/django/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/django/didgeridoo/currencies/__init__.py b/django/didgeridoo/currencies/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django/didgeridoo/currencies/admin.py b/django/didgeridoo/currencies/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/django/didgeridoo/currencies/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django/didgeridoo/currencies/apps.py b/django/didgeridoo/currencies/apps.py new file mode 100644 index 0000000..055501d --- /dev/null +++ b/django/didgeridoo/currencies/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CurrenciesConfig(AppConfig): + name = 'currencies' diff --git a/django/didgeridoo/currencies/exchange_rates.py b/django/didgeridoo/currencies/exchange_rates.py new file mode 100644 index 0000000..df33d6e --- /dev/null +++ b/django/didgeridoo/currencies/exchange_rates.py @@ -0,0 +1,133 @@ +from datetime import datetime +import urllib.request +import xml.etree.ElementTree as ET +import datetime as dt + + +""" +this method calls a rss/XML Resource +of Currency's and parses it to our +needed exchange rate values. +The return is a dictionary carring +Key:Value pairs of new currencys. +""" + + +def get_exchange_rate(): + # During weekends there are no updates. + # To develop i need a testresource. + # In that case i comment the Online Resource block and uncomment the + # development Block... + + # ~~~~~~~~~~~~~~~~~~~~~ + # Online Resource block: + # ~~~~~~~~~~~~~~~~~~~~~ + today = datetime.now().strftime("%Y-%m-%d") + SNB_URL = 'https://www.snb.ch/selector/de/mmr/exfeed/rss' + urlsocket = urllib.request.urlopen(SNB_URL) + root = ET.parse(urlsocket) + root = ET.ElementTree(root) + + # ~~~~~~~~~~~~~~~~~~~~~ + # development block: + # ~~~~~~~~~~~~~~~~~~~~~ + # today = "2018-01-03" + # try: + # root = ET.ElementTree(file='rss') + # except Exception as e: + # print('exchange_rates.py_urlsocket failed %s ( + # %s) on date: %s for %s' + # % (e, type(e), root)) + # ~~~~~~~~~~~~~~~~~~~~~ + + # Namespaces + ns = {'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + 'none': 'http://purl.org/rss/1.0/', + 'dc': 'http://purl.org/dc/elements/1.1/', + 'dcterms': 'http://purl.org/dc/terms/', + 'cb': 'http://www.cbwiki.net/wiki/index.php/Specification_1.2/' + } + # Pathvariables to XML Namespaces + rate_path = 'cb:statistics/cb:exchangeRate/' + observation_path = 'cb:statistics/cb:exchangeRate/cb:observation/' + exchange_rates = {} + for item in root.findall('none:item', ns): + # THE CURRENCY DATE: + 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 is with milliseconds: + try: + date = datetime.strptime(''.join( + datetime_str.rsplit(':', 1)), + "%Y-%m-%dT%H:%M:%S%z").strftime( + "%Y-%m-%d") + except: + try: + date = datetime.strptime(''.join( + datetime_str.rsplit(':', 1)), + "%Y-%m-%dT%H:%M:%S.%f%z").strftime( + "%Y-%m-%d") + except Exception as e: + print('%s (%s)' % (e, type(e))) + # Print dates for development: + # print("date:", date, "today:", today) + # only the values of today are used so check for date in XML: + if date == today: + target_currency = item.find(rate_path + + 'cb:targetCurrency', ns).text + value = float(item.find(observation_path + + 'cb:value', ns).text) + value = float(value) # convert to float + foreign_value = value # copy to new value to have both. + # because it's dangerous to check for present, i check for none + # here and have to do something in there so i set the target to 1. + if item.find(observation_path + 'cb:unit_mult', ns) is None: + unit_mult = float("1.0") + else: + # shift left by 2 digits with "/" + # https://stackoverflow.com/questions/8362792/ + # because some currencys differ widly from CHF + unit_mult = item.find(observation_path + + 'cb:unit_mult', ns).text + # unit_mult defaults to '0' so we check for 8 decimal + # values (2..-6) they represent the fracton value to + # calculate the correct decimalpoint. + if unit_mult == '2': # thinking of Bitcoins + unit_mult = '0.01' + if unit_mult == '1': + unit_mult = '0.10' + if unit_mult == '-1': + unit_mult = '10' + if unit_mult == '-2': # Japan Yen + unit_mult = '100' + if unit_mult == '-3': + unit_mult = '1000' + if unit_mult == '-4': + unit_mult = '10000' + if unit_mult == '-5': + unit_mult = '100000' + if unit_mult == '-6': # indian rupies + unit_mult = '1000000' + unit_mult = float(unit_mult) # convert to float + # calculate the Currency to CHF: + foreign_value = 1 / value + foreign_value *= unit_mult + value = value / unit_mult + # truncate it to decimal values provided by the xml: + foreign_value_round = round(foreign_value, 5) + # Print nice setup of all calculated currencys for Dev: + # print("date:", date, " 1 ", target_currency, " costs: ", + # CHFvalue, "CHF and 1 ", base_currency, " costs: ", + # FOREIGNvalue_round, target_currency) + exchange_rates.update( + {target_currency: foreign_value_round}) + # Print the Dictionary: + # print(exchange_rates) + else: + exchange_rates = "SNB did not update the currencies for today." + return(exchange_rates, today) + + # for development its preferable to see that the for loop is done: + # print('no more fresh data!') diff --git a/django/didgeridoo/currencies/migrations/0001_initial.py b/django/didgeridoo/currencies/migrations/0001_initial.py new file mode 100644 index 0000000..ee9f2f4 --- /dev/null +++ b/django/didgeridoo/currencies/migrations/0001_initial.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-01-09 18:21 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='ExchangeRate', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('exchange_rate_to_chf', models.DecimalField(decimal_places=5, max_digits=12)), + ], + ), + migrations.CreateModel( + name='ExchangeRate_date', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date', models.DateField(unique_for_date=True, verbose_name='%Y-%m-%d')), + ], + ), + migrations.CreateModel( + name='ExchangeRate_name', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200, unique=True)), + ], + ), + migrations.AddField( + model_name='exchangerate', + name='date', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='currencies.ExchangeRate_date'), + ), + migrations.AddField( + model_name='exchangerate', + name='name', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='currencies.ExchangeRate_name'), + ), + ] diff --git a/django/didgeridoo/currencies/migrations/__init__.py b/django/didgeridoo/currencies/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django/didgeridoo/currencies/models.py b/django/didgeridoo/currencies/models.py new file mode 100644 index 0000000..73a09ba --- /dev/null +++ b/django/didgeridoo/currencies/models.py @@ -0,0 +1,26 @@ +from django.db import models +from decimal import Decimal +import datetime + + +class ExchangeRate_name(models.Model): + name = models.CharField(max_length=200, unique=True) + + def __str__(self): + return self.name + + +class ExchangeRate_date(models.Model): + date = models.DateField('%Y-%m-%d', unique_for_date=True) + + def __str__(self): + return str(self.date) + + +class ExchangeRate(models.Model): + name = models.ForeignKey(ExchangeRate_name) + date = models.ForeignKey(ExchangeRate_date) + exchange_rate_to_chf = models.DecimalField(max_digits=12, decimal_places=5) + + def __str__(self): + return str(self.name) diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html new file mode 100644 index 0000000..851d38f --- /dev/null +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -0,0 +1,123 @@ + + + + + +
+

Currencies in CHF

+

{{ message }}

+

Frühere Daten:

+
+

US Dollars:

+ {% if currency_USD_list %} + + + {% for element in currency_USD_list %} + {% for key, value in element.items %} + + {% endfor %} + {% endfor %} + + {% for element in currency_USD_list %} + + {% for key, value in element.items %} + + {% endfor %} + + {% endfor %} +
{{ key }}
{{ value }}
+ {% else %} +

+ currency_USD_list missing. +

+ {% endif %} +
+

EURO:

+ {% if currency_EUR_list %} + + + {% for element in currency_EUR_list %} + {% for key, value in element.items %} + + {% endfor %} + {% endfor %} + + {% for element in currency_EUR_list %} + + {% for key, value in element.items %} + + {% endfor %} + + {% endfor %} +
{{ key }}
{{ value }}
+ {% else %} +

+ currency_EUR_list missing. +

+ {% endif %} +
+

Japanese Yenn:

+ {% if currency_JPY_list %} + + + {% for element in currency_JPY_list %} + {% for key, value in element.items %} + + {% endfor %} + {% endfor %} + + {% for element in currency_JPY_list %} + + {% for key, value in element.items %} + + {% endfor %} + + {% endfor %} +
{{ key }}
{{ value }}
+ {% else %} +

+ currency_JPY_list missing. +

+ {% endif %} +
+

Great Britain Pounds:

+ {% if currency_GBP_list %} + + + {% for element in currency_GBP_list %} + {% for key, value in element.items %} + + {% endfor %} + {% endfor %} + + {% for element in currency_GBP_list %} + + {% for key, value in element.items %} + + {% endfor %} + + {% endfor %} +
{{ key }}
{{ value }}
+ {% else %} +

+ currency_GBP_list missing. +

+ {% endif %} +
+ +
+ + diff --git a/django/didgeridoo/currencies/tests.py b/django/didgeridoo/currencies/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django/didgeridoo/currencies/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py new file mode 100644 index 0000000..2804c74 --- /dev/null +++ b/django/didgeridoo/currencies/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url +from currencies.views import currencies + + +urlpatterns = [ + url(r'^currencies/$', currencies), +] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py new file mode 100644 index 0000000..d4a2f32 --- /dev/null +++ b/django/didgeridoo/currencies/views.py @@ -0,0 +1,175 @@ +from django.shortcuts import render +import datetime +from currencies.models import (ExchangeRate, + ExchangeRate_date, + ExchangeRate_name) +from currencies import exchange_rates + + +def currencies(request): + # this function fetches the data from exchange_rates.py + # evaluates if the values are already stored and + # prepares the view all dynamicaly. + # It can grow in terms of more Currencies over time automaticaly. + # try: + today = '1970-01-01' + raw_data = '' + raw_data, today = exchange_rates.get_exchange_rate() + # except Exception as e: + # print('get_exchange_rate() %s (%s) on %s' + # % (e, type(e), today)) + message_no = "Already querried today: " + message_yes = " Updated successfully: " + count_raw_data = 0 + if raw_data == "SNB did not update the currencies for today.": + message = """Die SNB hat die Währungsliste noch nicht aktualisiert.""" + else: + for currency, rate in raw_data.items(): + count_raw_data += 1 + if ExchangeRate.objects.filter( + date__date=today, + name__name=currency): + message_no += currency + ", " + # A: https://stackoverflow.com/a/27802801/4061870 + else: + if ExchangeRate_date.objects.filter(date=today)[:1]: + try: + # lustigerweise gibt .values() den value und den id + # zurück. Ohne .values() gibts nur den "value" + date_dict = ExchangeRate_date.objects.filter( + date=today).values() + date = date_dict[0]['date'] + date_id = date_dict[0]['id'] + except Exception as e: + print('exdate_exists %s (%s) on %s' + % (e, type(e), today)) + else: + try: + exdate = ExchangeRate_date.objects.create( + date=today) + exdate.save() + except Exception as e: + print('exdate_not_exists %s (%s) for %s' + % (e, type(e), today)) + if ExchangeRate_name.objects.filter( + name=currency)[:1]: + try: + name_dict = ExchangeRate_name.objects.filter( + name=currency).values() + name = name_dict[0]['name'] + name_id = name_dict[0]['id'] + except Exception as e: + print('exname_exists %s (%s) on %s' + % (e, type(e), currency)) + else: + try: + exname = ExchangeRate_name.objects.create( + name=currency) + exname.save() + except Exception as e: + print('exname_not_exists %s (%s) on %s' + % (e, type(e), currency)) + try: + exrate = ExchangeRate.objects.create( + # name_id=name_id, + name_id=ExchangeRate_name.objects.get( + name=currency).id, + # date_id=date_id, + date_id=ExchangeRate_date.objects.get( + date=today).id, + exchange_rate_to_chf=rate, + ) + exrate.save() + message_yes += currency + ", " + + except Exception as e: + print('exrate_create %s (%s) on %s for %s' + % (e, type(e), currency, today)) + + # prepare messages: + message_no = message_no[::-1] # invert the string + message_no = message_no.replace(",", "!", 1) # replace first , with ! + message_no = message_no[::-1] # invert the string back + message_yes = message_yes[::-1] # invert the string + message_yes = message_yes.replace(",", "!", 1) # replace first , with ! + message_yes = message_yes[::-1] # invert the string back + + if len(message_no) > 24 and len(message_yes) > 23: + message = message_no + message_yes + elif len(message_no) > 24: + message = message_no + elif len(message_yes) > 23: + message = message_yes + elif datetime.datetime.today().isoweekday() == 6: + message = """Die Abfrage wurde ohne ergebniss beendet. + Es ist Samstag, die SNB publiziert nur an Arbeitstagen neue Kurse... + """ + elif datetime.datetime.today().isoweekday() == 7: + message = """Die Abfrage wurde ohne ergebniss beendet. + Es ist Sonntag, die SNB publiziert nur an Arbeitstagen neue Kurse... + """ + else: + message = """Die Abfrage wurde ohne ergebniss beendet. + Kann es sein dass die SNB aufgrund eines Feiertages geschlossen ist? + """ + currency_list = ExchangeRate.objects.all() + currency_USD_list = ExchangeRate.objects.filter(name__name='USD').values() + currency_EUR_list = ExchangeRate.objects.filter(name__name='EUR').values() + currency_JPY_list = ExchangeRate.objects.filter(name__name='JPY').values() + currency_GBP_list = ExchangeRate.objects.filter(name__name='GBP').values() + # ------------------------------------------------------------------- + # ------------------------------------------------------------------- + # I leave this part in the document as history. + # Problem is that i get the expected List with dictionaries like: + # view_currencies_list[ + # {'date': '2017-12-29, 'USD':'1.00', 'EUR':'1.00', 'GBP':'1.00', 'JPY':'1.00'}, + # {'date': '2017-12-30, 'USD':'1.00', 'EUR':'1.00', 'GBP':'1.00', 'JPY':'1.00'}, + # ] + # but the dict of 'date:' does not seam to deliver the same values as + # the dict's of key name:'USD' im not able to fix this in moment. + # nor am i able to generate a HTML table with date | USD | EUR | ... + # ------------------------------------------------------------------- + # ------------------------------------------------------------------- + # prepare data to be displayed in a html table: + # https://stackoverflow.com/questions/8749158/removing-duplicates-from-dictionary#8749473 + # A: https://stackoverflow.com/questions/37205793/django-values-list-vs-values#37205928 + # B: https://stackoverflow.com/questions/6521892/how-to-access-a-dictionary-key-value-present-inside-a-list + # # search for currencies in a date and apend them to the list + # view_currency_list = [] + # view_currencies_list = ExchangeRate_name.objects.all() + # view_dates_list = ExchangeRate_date.objects.all() + # count_date = 0 + # count_currencies = 0 + # for view_date in view_dates_list: + # count_date += 1 + # view_currency_dict = {view_date} + # # view_currency_dict.update({}) + # for view_currency in view_currencies_list: + # count_currencies += 1 + # try: + # x = ExchangeRate.objects.filter(date__date=str( + # view_date), + # name__name=str( + # view_currency + # )).values() # A + # view_exchange_rate_to_chf = x[0]['exchange_rate_to_chf'] + # except Exception as e: + # print('prepare_view %s (%s) for %s on %s is %s' + # % (e, type(e), view_currency, view_date, + # view_exchange_rate_to_chf)) + # view_exchange_rate_to_chf = " " + # + # view_currency_dict.update({view_currency: + # view_exchange_rate_to_chf}) # B + # + # view_currency_list.append(view_currency_dict) + # assert False + return render(request, + 'currencies/index.html', + {'currency_list': currency_list, + 'currency_USD_list': currency_USD_list, + 'currency_EUR_list': currency_EUR_list, + 'currency_JPY_list': currency_JPY_list, + 'currency_GBP_list': currency_GBP_list, + 'count_raw_data': count_raw_data, + 'message': message}) diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index b811f2a..71b26b2 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -35,6 +35,7 @@ ALLOWED_HOSTS = [ # Application definition INSTALLED_APPS = [ + 'currencies', 'webshop.apps.WebshopConfig', 'django_extensions', 'django.contrib.admin', @@ -43,7 +44,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', -] + ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', diff --git a/django/didgeridoo/didgeridoo/urls.py b/django/didgeridoo/didgeridoo/urls.py index be44997..87e1e57 100644 --- a/django/didgeridoo/didgeridoo/urls.py +++ b/django/didgeridoo/didgeridoo/urls.py @@ -20,6 +20,6 @@ from django.conf.urls.static import static urlpatterns = [ url(r'', include('webshop.urls')), - url(r'^admin/', admin.site.urls), + url(r'', include('currencies.urls')), url(r'^admin/', admin.site.urls), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/django/didgeridoo/rss b/django/didgeridoo/rss new file mode 100644 index 0000000..b6be892 --- /dev/null +++ b/django/didgeridoo/rss @@ -0,0 +1,621 @@ + + + + SNB Devisenkurse + https://www.snb.ch/de/ifor/media/id/media_rss + Schweizerische Nationalbank (SNB): Devisenkurse (Ankauf Zürich 11 Uhr) + + + + + + + + + + + + + + + + + + + + + + + + + SNB + Copyright © Schweizerische Nationalbank, Zürich (Schweiz) 2017 + https://www.snb.ch/de/srv/id/disclaimer + 2017-11-28T07:50:22+01:00 + + + CH: 1.3081 CHF = 1 GBP 2017-11-27 Tägliche Kurse (11:00) + https://www.snb.ch + 1 GBP = 1.3081 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.767+01:00) + 2018-01-03T12:16:53.767+01:00 + de + + + CH + SNB + + + + + 1.3081 + CHF + 4 + + CHF + GBP + Tägliche Kurse (11:00) + + + daily + 2017-11-27 + + + + + + CH: 0.8813 CHF = 100 JPY 2017-11-27 Tägliche Kurse (11:00) + https://www.snb.ch + 100 JPY = 0.8813 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.760+01:00) + 2018-01-03T12:16:53.760+01:00 + de + + + CH + SNB + + + + + 10000.8813 + CHF + -2 + 4 + + CHF + JPY + Tägliche Kurse (11:00) + + + daily + 2017-11-27 + + + + + + CH: 1.1697 CHF = 1 EUR 2017-11-27 Tägliche Kurse (11:00) + https://www.snb.ch + 1 EUR = 1.1697 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.750+01:00) + 2018-01-03T12:16:53.750+01:00 + de + + + CH + SNB + + + + + 1.1697 + CHF + 4 + + CHF + EUR + Tägliche Kurse (11:00) + + + daily + 2017-11-27 + + + + + + CH: 0.9803 CHF = 1 USD 2017-11-27 Tägliche Kurse (11:00) + https://www.snb.ch + 1 USD = 0.9803 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.737+01:00) + 2018-01-03T12:16:53.737+01:00 + de + + + CH + SNB + + + + + 0.9803 + CHF + 4 + + CHF + USD + Tägliche Kurse (11:00) + + + daily + 2017-11-27 + + + + + + CH: 1.3072 CHF = 1 GBP 2017-11-24 Tägliche Kurse (11:00) + https://www.snb.ch + 1 GBP = 1.3072 CHF (Tägliche Kurse (11:00); 2017-11-24T12:19:49.733+01:00) + 2017-11-24T12:19:49.733+01:00 + de + + + CH + SNB + + + + + 1.3072 + CHF + 4 + + CHF + GBP + Tägliche Kurse (11:00) + + + daily + 2017-11-24 + + + + + + CH: 0.8806 CHF = 100 JPY 2017-11-24 Tägliche Kurse (11:00) + https://www.snb.ch + 100 JPY = 0.8806 CHF (Tägliche Kurse (11:00); 2017-11-24T12:19:49.717+01:00) + 2017-11-24T12:19:49.717+01:00 + de + + + CH + SNB + + + + + 0.8806 + CHF + -2 + 4 + + CHF + JPY + Tägliche Kurse (11:00) + + + daily + 2017-11-24 + + + + + + CH: 1.1644 CHF = 1 EUR 2017-11-24 Tägliche Kurse (11:00) + https://www.snb.ch + 1 EUR = 1.1644 CHF (Tägliche Kurse (11:00); 2017-11-24T12:19:49.710+01:00) + 2017-11-24T12:19:49.710+01:00 + de + + + CH + SNB + + + + + 1.1644 + CHF + 4 + + CHF + EUR + Tägliche Kurse (11:00) + + + daily + 2017-11-24 + + + + + + CH: 0.9809 CHF = 1 USD 2017-11-24 Tägliche Kurse (11:00) + https://www.snb.ch + 1 USD = 0.9809 CHF (Tägliche Kurse (11:00); 2017-11-24T12:19:49.703+01:00) + 2017-11-24T12:19:49.703+01:00 + de + + + CH + SNB + + + + + 0.9809 + CHF + 4 + + CHF + USD + Tägliche Kurse (11:00) + + + daily + 2017-11-24 + + + + + + CH: 1.3052 CHF = 1 GBP 2017-11-23 Tägliche Kurse (11:00) + https://www.snb.ch + 1 GBP = 1.3052 CHF (Tägliche Kurse (11:00); 2017-11-23T12:36:46.040+01:00) + 2017-11-23T12:36:46.040+01:00 + de + + + CH + SNB + + + + + 1.3052 + CHF + 4 + + CHF + GBP + Tägliche Kurse (11:00) + + + daily + 2017-11-23 + + + + + + CH: 0.8816 CHF = 100 JPY 2017-11-23 Tägliche Kurse (11:00) + https://www.snb.ch + 100 JPY = 0.8816 CHF (Tägliche Kurse (11:00); 2017-11-23T12:36:46.030+01:00) + 2017-11-23T12:36:46.030+01:00 + de + + + CH + SNB + + + + + 0.8816 + CHF + -2 + 4 + + CHF + JPY + Tägliche Kurse (11:00) + + + daily + 2017-11-23 + + + + + + CH: 1.1617 CHF = 1 EUR 2017-11-23 Tägliche Kurse (11:00) + https://www.snb.ch + 1 EUR = 1.1617 CHF (Tägliche Kurse (11:00); 2017-11-23T12:36:46.027+01:00) + 2017-11-23T12:36:46.027+01:00 + de + + + CH + SNB + + + + + 1.1617 + CHF + 4 + + CHF + EUR + Tägliche Kurse (11:00) + + + daily + 2017-11-23 + + + + + + CH: 0.9811 CHF = 1 USD 2017-11-23 Tägliche Kurse (11:00) + https://www.snb.ch + 1 USD = 0.9811 CHF (Tägliche Kurse (11:00); 2017-11-23T12:36:46.017+01:00) + 2017-11-23T12:36:46.017+01:00 + de + + + CH + SNB + + + + + 0.9811 + CHF + 4 + + CHF + USD + Tägliche Kurse (11:00) + + + daily + 2017-11-23 + + + + + + CH: 1.3109 CHF = 1 GBP 2017-11-22 Tägliche Kurse (11:00) + https://www.snb.ch + 1 GBP = 1.3109 CHF (Tägliche Kurse (11:00); 2017-11-22T12:24:04.110+01:00) + 2017-11-22T12:24:04.110+01:00 + de + + + CH + SNB + + + + + 1.3109 + CHF + 4 + + CHF + GBP + Tägliche Kurse (11:00) + + + daily + 2017-11-22 + + + + + + CH: 0.8827 CHF = 100 JPY 2017-11-22 Tägliche Kurse (11:00) + https://www.snb.ch + 100 JPY = 0.8827 CHF (Tägliche Kurse (11:00); 2017-11-22T12:24:04.103+01:00) + 2017-11-22T12:24:04.103+01:00 + de + + + CH + SNB + + + + + 0.8827 + CHF + -2 + 4 + + CHF + JPY + Tägliche Kurse (11:00) + + + daily + 2017-11-22 + + + + + + CH: 1.1633 CHF = 1 EUR 2017-11-22 Tägliche Kurse (11:00) + https://www.snb.ch + 1 EUR = 1.1633 CHF (Tägliche Kurse (11:00); 2017-11-22T12:24:04.090+01:00) + 2017-11-22T12:24:04.090+01:00 + de + + + CH + SNB + + + + + 1.1633 + CHF + 4 + + CHF + EUR + Tägliche Kurse (11:00) + + + daily + 2017-11-22 + + + + + + CH: 0.9894 CHF = 1 USD 2017-11-22 Tägliche Kurse (11:00) + https://www.snb.ch + 1 USD = 0.9894 CHF (Tägliche Kurse (11:00); 2017-11-22T12:24:04.083+01:00) + 2017-11-22T12:24:04.083+01:00 + de + + + CH + SNB + + + + + 0.9894 + CHF + 4 + + CHF + USD + Tägliche Kurse (11:00) + + + daily + 2017-11-22 + + + + + + CH: 1.3151 CHF = 1 GBP 2017-11-21 Tägliche Kurse (11:00) + https://www.snb.ch + 1 GBP = 1.3151 CHF (Tägliche Kurse (11:00); 2017-11-21T12:19:20.370+01:00) + 2017-11-21T12:19:20.370+01:00 + de + + + CH + SNB + + + + + 1.3151 + CHF + 4 + + CHF + GBP + Tägliche Kurse (11:00) + + + daily + 2017-11-21 + + + + + + CH: 0.8832 CHF = 100 JPY 2017-11-21 Tägliche Kurse (11:00) + https://www.snb.ch + 100 JPY = 0.8832 CHF (Tägliche Kurse (11:00); 2017-11-21T12:19:20.363+01:00) + 2017-11-21T12:19:20.363+01:00 + de + + + CH + SNB + + + + + 0.8832 + CHF + -2 + 4 + + CHF + JPY + Tägliche Kurse (11:00) + + + daily + 2017-11-21 + + + + + + CH: 1.1647 CHF = 1 EUR 2017-11-21 Tägliche Kurse (11:00) + https://www.snb.ch + 1 EUR = 1.1647 CHF (Tägliche Kurse (11:00); 2017-11-21T12:19:20.360+01:00) + 2017-11-21T12:19:20.360+01:00 + de + + + CH + SNB + + + + + 1.1647 + CHF + 4 + + CHF + EUR + Tägliche Kurse (11:00) + + + daily + 2017-11-21 + + + + + + CH: 0.9930 CHF = 1 USD 2017-11-21 Tägliche Kurse (11:00) + https://www.snb.ch + 1 USD = 0.9930 CHF (Tägliche Kurse (11:00); 2017-11-21T12:19:20.343+01:00) + 2017-11-21T12:19:20.343+01:00 + de + + + CH + SNB + + + + + 0.9930 + CHF + 4 + + CHF + USD + Tägliche Kurse (11:00) + + + daily + 2017-11-21 + + + + + diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index e168aa3..3bb3442 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -2,7 +2,7 @@ from decimal import Decimal from django.core.validators import MinValueValidator from django.db import models from django.contrib.auth.models import User -import datetime +from django.utils import timezone class Option(models.Model): @@ -28,14 +28,6 @@ class ArticleStatus(models.Model): return self.name -class ExchangeRate(models.Model): - name = models.CharField(max_length=200, unique=True) - exchange_rate_to_chf = models.FloatField(max_length=5) - - def __str__(self): - return self.name - - # Create your models here. class Category(models.Model): name = models.CharField(max_length=200, unique=True) @@ -94,7 +86,7 @@ class Order(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) article = models.ManyToManyField(Article, through='OrderPosition') status = models.ForeignKey(OrderStatus) - date = models.DateTimeField(default=datetime.datetime.now()) + date = models.DateTimeField(default=timezone.now) class OrderPosition(models.Model):