diff --git a/django/didgeridoo/currencies/exchange_rates.py b/django/didgeridoo/currencies/exchange_rates.py index bf23ab6..43afbc7 100644 --- a/django/didgeridoo/currencies/exchange_rates.py +++ b/django/didgeridoo/currencies/exchange_rates.py @@ -31,7 +31,7 @@ def parse_rss(urlsocket): def pass_local_file(): rss_tree = ET.ElementTree(file='rss') return(rss_tree) - + def get_exchange_rate(rss_tree, ns): # Pathvariables to XML Namespaces with @@ -111,5 +111,4 @@ def get_exchange_rate(rss_tree, ns): 'exchangerate': foreign_value_round}] exchange_rates.append(data) # Print the Dictionary: - print(exchange_rates) return(exchange_rates) diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 02259d9..6dc1071 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -1,8 +1,17 @@ from django import forms -from currencies.models import ExchangeRate_name +from currencies.models import ExchangeRate, ExchangeRate_name class CurrenciesForm(forms.Form): currencies = forms.ModelChoiceField( queryset=ExchangeRate_name.objects.all(), - required=False, empty_label='CHF') + required=False, + empty_label='CHF', + label='CURENCIES', + # widget=forms.Select( + # attrs={ + # 'onchange': 'currency.submit();', + # 'class': 'btn-primary dropdown-toggle' + # } + #) + ) diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index 2f28ccb..4c9ef7b 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -1,88 +1,28 @@ {% extends "webshop/base.html" %} {% block section_title %}Currencies in CHF{% endblock %} {% block content %} -

{{ message }}

-

Frühere Daten:

-

US Dollars:

- {% if currency_USD_list %} +

Currency List:

+ {% if ordered_currency_list %} + - {% for currency in currency_USD_list %} + {% for currency in ordered_currency_list %} - + + {% endfor %}
DATENAME RATE
{{ currency.date.date }}{{ currency.date }}{{ currency.name }} {{ currency.exchange_rate_to_chf }}
+

{{ message }}

{% else %} +

- currency_USD_list missing. + currency_list missing.

{% endif %} -
-

EURO:

- {% if currency_EUR_list %} - - - - - - {% for currency in currency_EUR_list %} - - - - - {% endfor %} -
DATERATE
{{ currency.date.date }}{{ currency.exchange_rate_to_chf }}
- {% else %} -

- currency_EUR_list missing. -

- {% endif %} -
-

Japanese Yenn:

- {% if currency_JPY_list %} - - - - - - {% for currency in currency_JPY_list %} - - - - - {% endfor %} - -
DATERATE
{{ currency.date.date }}{{ currency.exchange_rate_to_chf }}
- {% else %} -

- currency_JPY_list missing. -

- {% endif %} -
-

Great Britain Pounds:

- {% if currency_GBP_list %} - - - - - - {% for currency in currency_GBP_list %} - - - - - {% endfor %} - -
DATERATE
{{ currency.date.date }}{{ currency.exchange_rate_to_chf }}
- {% else %} -

- currency_GBP_list missing. -

- {% endif %} {% endblock %} diff --git a/django/didgeridoo/currencies/templatetags/customfilters.py b/django/didgeridoo/currencies/templatetags/customfilters.py deleted file mode 100644 index a30e2ab..0000000 --- a/django/didgeridoo/currencies/templatetags/customfilters.py +++ /dev/null @@ -1,12 +0,0 @@ -from django import template - - -register = template.Library() - - -@register.filter() -def boldcoffee(value): - # currency_of_customer = request.session['currency'] - return '%s !!gefiltert!!' % value - - # excample filter: {{ article.price_in_chf|boldcoffee }} diff --git a/django/didgeridoo/currencies/urls.py b/django/didgeridoo/currencies/urls.py index aa24648..91fa530 100644 --- a/django/didgeridoo/currencies/urls.py +++ b/django/didgeridoo/currencies/urls.py @@ -1,9 +1,6 @@ from django.conf.urls import url -from currencies.views import currencies, currency_update +from currencies.views import currencies urlpatterns = [ url(r'^currencies/$', currencies), - url(r'^ajax/currency_update/$', - currency_update, - name='currency_update'), ] diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index b49ae44..4a5ac1f 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -1,6 +1,5 @@ from django.shortcuts import render from datetime import datetime -from django.views.generic.edit import UpdateView from currencies.models import (ExchangeRate, ExchangeRate_date, ExchangeRate_name) @@ -8,20 +7,6 @@ from currencies import exchange_rates from django.http import JsonResponse -def currency_update(request): - # https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html - if request.GET.get('currency_update', None) == 'CHF': - data = {} - else: - currency = request.GET.get('currency_update', None) - data = ExchangeRate.objects.filter( - name__name=currency).values( - 'exchange_rate_to_chf').latest( - 'date__date') - print('currency:', currency, 'data: ', data) - return JsonResponse(data) - - def currencies(request): """this function fetches the data from swiss national bank @@ -57,7 +42,7 @@ def currencies(request): message_offline = """ Are you offline? - useing stored currencies. This does not efect you, but your purchase prices will be - recalculated as soon as you submit your Order. + recalculated as soon as you submit your Order.
""" try: raw_data = exchange_rates.get_exchange_rate(rss_tree, ns) @@ -163,32 +148,21 @@ def currencies(request): elif datetime.datetime.today().isoweekday() == 6: message = """Die Abfrage wurde ohne ergebniss beendet. Es ist Samstag, die SNB publiziert nur an Arbeitstagen - neue Kurse... + 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... + neue Kurse...
""" else: - message = """Die Abfrage wurde ohne ergebniss beendet. + message = """Die Abfrage wurde ohne ergebniss beendet.
""" # know we can query our data for presentaton: - currency_list = ExchangeRate.objects.all() - currency_USD_list = ExchangeRate.objects.filter( - name__name='USD').order_by('date__date') - currency_EUR_list = ExchangeRate.objects.filter( - name__name='EUR').order_by('date__date') - currency_JPY_list = ExchangeRate.objects.filter( - name__name='JPY').order_by('date__date') - currency_GBP_list = ExchangeRate.objects.filter( - name__name='GBP').order_by('date__date') + ordered_currency_list = ExchangeRate.objects.order_by('name', 'date') + # and publish it on template: 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, + {'ordered_currency_list': ordered_currency_list, 'message': message}) diff --git a/django/didgeridoo/rss b/django/didgeridoo/rss index b6be892..d7eafcc 100644 --- a/django/didgeridoo/rss +++ b/django/didgeridoo/rss @@ -1,621 +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 - - - - - + + + +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) 2018 +https://www.snb.ch/de/srv/id/disclaimer +2018-02-27T21:05:28+01:00 + + +CH: 1.1549 CHF = 1 EUR 2018-02-27 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#EUR +1 EUR = 1.1549 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:35+01:00) +2018-02-27T12:06:35+01:00 +de + + +CH +SNB + + + + +1.1549 +CHF +4 + +CHF +EUR +Tägliche Kurse (11:00) + + +daily +2018-02-27 + + + + + +CH: 1.3069 CHF = 1 GBP 2018-02-27 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#GBP +1 GBP = 1.3069 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:35+01:00) +2018-02-27T12:06:35+01:00 +de + + +CH +SNB + + + + +1.3069 +CHF +4 + +CHF +GBP +Tägliche Kurse (11:00) + + +daily +2018-02-27 + + + + + +CH: 0.8753 CHF = 100 JPY 2018-02-27 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#JPY +100 JPY = 0.8753 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:35+01:00) +2018-02-27T12:06:35+01:00 +de + + +CH +SNB + + + + +0.8753 +CHF +-2 +4 + +CHF +JPY +Tägliche Kurse (11:00) + + +daily +2018-02-27 + + + + + +CH: 0.9363 CHF = 1 USD 2018-02-27 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#USD +1 USD = 0.9363 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:35+01:00) +2018-02-27T12:06:35+01:00 +de + + +CH +SNB + + + + +0.9363 +CHF +4 + +CHF +USD +Tägliche Kurse (11:00) + + +daily +2018-02-27 + + + + + +CH: 1.1520 CHF = 1 EUR 2018-02-26 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#EUR +1 EUR = 1.1520 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:50+01:00) +2018-02-27T12:06:50+01:00 +de + + +CH +SNB + + + + +1.1520 +CHF +4 + +CHF +EUR +Tägliche Kurse (11:00) + + +daily +2018-02-26 + + + + + +CH: 1.3126 CHF = 1 GBP 2018-02-26 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#GBP +1 GBP = 1.3126 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:50+01:00) +2018-02-27T12:06:50+01:00 +de + + +CH +SNB + + + + +1.3126 +CHF +4 + +CHF +GBP +Tägliche Kurse (11:00) + + +daily +2018-02-26 + + + + + +CH: 0.8754 CHF = 100 JPY 2018-02-26 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#JPY +100 JPY = 0.8754 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:50+01:00) +2018-02-27T12:06:50+01:00 +de + + +CH +SNB + + + + +0.8754 +CHF +-2 +4 + +CHF +JPY +Tägliche Kurse (11:00) + + +daily +2018-02-26 + + + + + +CH: 0.9331 CHF = 1 USD 2018-02-26 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#USD +1 USD = 0.9331 CHF (Tägliche Kurse (11:00); 2018-02-27T12:06:50+01:00) +2018-02-27T12:06:50+01:00 +de + + +CH +SNB + + + + +0.9331 +CHF +4 + +CHF +USD +Tägliche Kurse (11:00) + + +daily +2018-02-26 + + + + + +CH: 1.1499 CHF = 1 EUR 2018-02-23 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#EUR +1 EUR = 1.1499 CHF (Tägliche Kurse (11:00); 2018-02-26T12:20:51+01:00) +2018-02-26T12:20:51+01:00 +de + + +CH +SNB + + + + +1.1499 +CHF +4 + +CHF +EUR +Tägliche Kurse (11:00) + + +daily +2018-02-23 + + + + + +CH: 1.3058 CHF = 1 GBP 2018-02-23 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#GBP +1 GBP = 1.3058 CHF (Tägliche Kurse (11:00); 2018-02-26T12:20:51+01:00) +2018-02-26T12:20:51+01:00 +de + + +CH +SNB + + + + +1.3058 +CHF +4 + +CHF +GBP +Tägliche Kurse (11:00) + + +daily +2018-02-23 + + + + + +CH: 0.8738 CHF = 100 JPY 2018-02-23 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#JPY +100 JPY = 0.8738 CHF (Tägliche Kurse (11:00); 2018-02-26T12:20:51+01:00) +2018-02-26T12:20:51+01:00 +de + + +CH +SNB + + + + +0.8738 +CHF +-2 +4 + +CHF +JPY +Tägliche Kurse (11:00) + + +daily +2018-02-23 + + + + + +CH: 0.9340 CHF = 1 USD 2018-02-23 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#USD +1 USD = 0.9340 CHF (Tägliche Kurse (11:00); 2018-02-26T12:20:51+01:00) +2018-02-26T12:20:51+01:00 +de + + +CH +SNB + + + + +0.9340 +CHF +4 + +CHF +USD +Tägliche Kurse (11:00) + + +daily +2018-02-23 + + + + + +CH: 1.1527 CHF = 1 EUR 2018-02-22 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#EUR +1 EUR = 1.1527 CHF (Tägliche Kurse (11:00); 2018-02-23T12:18:14+01:00) +2018-02-23T12:18:14+01:00 +de + + +CH +SNB + + + + +1.1527 +CHF +4 + +CHF +EUR +Tägliche Kurse (11:00) + + +daily +2018-02-22 + + + + + +CH: 1.3026 CHF = 1 GBP 2018-02-22 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#GBP +1 GBP = 1.3026 CHF (Tägliche Kurse (11:00); 2018-02-23T12:18:14+01:00) +2018-02-23T12:18:14+01:00 +de + + +CH +SNB + + + + +1.3026 +CHF +4 + +CHF +GBP +Tägliche Kurse (11:00) + + +daily +2018-02-22 + + + + + +CH: 0.8744 CHF = 100 JPY 2018-02-22 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#JPY +100 JPY = 0.8744 CHF (Tägliche Kurse (11:00); 2018-02-23T12:18:14+01:00) +2018-02-23T12:18:14+01:00 +de + + +CH +SNB + + + + +0.8744 +CHF +-2 +4 + +CHF +JPY +Tägliche Kurse (11:00) + + +daily +2018-02-22 + + + + + +CH: 0.9375 CHF = 1 USD 2018-02-22 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#USD +1 USD = 0.9375 CHF (Tägliche Kurse (11:00); 2018-02-23T12:18:14+01:00) +2018-02-23T12:18:14+01:00 +de + + +CH +SNB + + + + +0.9375 +CHF +4 + +CHF +USD +Tägliche Kurse (11:00) + + +daily +2018-02-22 + + + + + +CH: 1.1552 CHF = 1 EUR 2018-02-21 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#EUR +1 EUR = 1.1552 CHF (Tägliche Kurse (11:00); 2018-02-22T12:21:03+01:00) +2018-02-22T12:21:03+01:00 +de + + +CH +SNB + + + + +1.1552 +CHF +4 + +CHF +EUR +Tägliche Kurse (11:00) + + +daily +2018-02-21 + + + + + +CH: 1.3082 CHF = 1 GBP 2018-02-21 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#GBP +1 GBP = 1.3082 CHF (Tägliche Kurse (11:00); 2018-02-22T12:21:03+01:00) +2018-02-22T12:21:03+01:00 +de + + +CH +SNB + + + + +1.3082 +CHF +4 + +CHF +GBP +Tägliche Kurse (11:00) + + +daily +2018-02-21 + + + + + +CH: 0.8713 CHF = 100 JPY 2018-02-21 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#JPY +100 JPY = 0.8713 CHF (Tägliche Kurse (11:00); 2018-02-22T12:21:03+01:00) +2018-02-22T12:21:03+01:00 +de + + +CH +SNB + + + + +0.8713 +CHF +-2 +4 + +CHF +JPY +Tägliche Kurse (11:00) + + +daily +2018-02-21 + + + + + +CH: 0.9367 CHF = 1 USD 2018-02-21 Tägliche Kurse (11:00) +https://www.snb.ch/de/iabout/stat/statpub/zidea/id/current_interest_exchange_rates/3#USD +1 USD = 0.9367 CHF (Tägliche Kurse (11:00); 2018-02-22T12:21:03+01:00) +2018-02-22T12:21:03+01:00 +de + + +CH +SNB + + + + +0.9367 +CHF +4 + +CHF +USD +Tägliche Kurse (11:00) + + +daily +2018-02-21 + + + + + diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js deleted file mode 100644 index fefddab..0000000 --- a/django/didgeridoo/static/js/app.js +++ /dev/null @@ -1,30 +0,0 @@ - $("#id_currency_update").change(function () { - var currency_update = $(this).val(); - $("#id_currency_update").val(currency_update); - $.ajax({ - url: '/ajax/currency_update/', - data: { - 'currency_update': currency_update - }, - dataType: 'json', - success: function (data) { - var foo = jQuery.parseJSON(data); - alert("es pop auf! --dies kommt von: static/js/app.js--." + foo.currency_update); - - } - }); - }); - - //document.getElementById('id_currency_update').getElementsByTagName('currency_update') - //$("#id_currency_update").val('USD').selected = 'selected'; - - //https://stackoverflow.com/a/30489067/4061870 - // var obj = document.getElementById("id_currency_update"); - // for(i=0; i

Username: {{ request.user.username }}

-

Salutation: {{ person.salutation }}

-

Firstname: {{ request.user.first_name }}

-

Lastname: {{ request.user.last_name }}

+

Name: + {{ person.salutation }} + {{ request.user.first_name }} + {{ request.user.last_name }}

+

Street: {{ person.street_name }} {{ person.street_number }}

City: {{ person.city }}

-

Street: {{ person.street_name }}

-

Streetnumber: {{ person.street_number }}

{% csrf_token %} {{ form.as_p }}
+{% if order_list_zip %} +
+

Orders:

+ + + + + + + {% for order, order_positions_count in order_list_zip %} + + + + + + {% endfor %} +
IDDATESTATUS
{{ order.id }}{{ order.date }} + {{ order.status }} +
+{% else %} +

+ you don't have Ordered anything yet. + As soon as you Purchase anything from us you can see your Orders here. +

+{% endif %} {% endblock %} diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html index f611601..0c409da 100644 --- a/django/didgeridoo/webshop/templates/webshop/article_details.html +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -15,7 +15,9 @@

{% else %} -

please login to fill your basket...

+

+ please login to fill your basket... +

{% endif %} {% for picture in picture_list %}

diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index 94e473e..6c92b86 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -81,7 +81,7 @@ Currencies
  • - How to use + How to use
  • @@ -93,7 +93,6 @@ - diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index f04590a..4c2dfd7 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,5 +1,4 @@ {% extends "webshop/base.html" %} -{% load customfilters %} {% block section_title %}Articles{% endblock %} {% block content %} diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index 6390f7b..3800432 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -13,12 +13,12 @@ {% else %}
  • LOGIN
  • {% endif %} -
  • {% if article_view %}
    {{ currencies_form.as_ul }} + {% csrf_token %}
  • - {% csrf_token %}
    {% endif %}
  • diff --git a/django/didgeridoo/webshop/templates/webshop/order.html b/django/didgeridoo/webshop/templates/webshop/order.html index 1ffcde5..301f7aa 100644 --- a/django/didgeridoo/webshop/templates/webshop/order.html +++ b/django/didgeridoo/webshop/templates/webshop/order.html @@ -1,7 +1,70 @@ {% extends "webshop/base.html" %} -{% load customfilters %} {% block section_title %}Order{% endblock %} {% block content %} -

    Your order was submitted.

    -

    Thank you for Purchase.

    + {% if order %} +

    Your order was submitted on: + {{ order.date }}, current Status is: + {{ order.status }}. +

    + {% else %} +

    + + Orderdetails are not avalable. + +

    + {% endif %} +

    List of Items in your Order:

    + {% if order_position_list_zip %} + + + + + + + + + + + {% for order_position, price, pos_price in order_position_list_zip %} + + + + + + + + + + {% endfor %} + + + + +
    POS.ART#NAMESTOCKAMOUNTPRICE p.pce.POSITION PRICE
    {{ order_position.id }}{{ order_position.article.id }} + + {{ order_position.article.name }} + + {{ order_position.article.stock }}{{ order_position.amount }} + {{ price }} + {{ currency_name }} + + {{ pos_price }} {{ currency_name }} +
    + +
    Total:
    +
    {{ total }} {{ currency_name }}
    +
    +

    Thank you for Purchase.

    + {% else %} +

    + + This order is empty. Howcome? + +

    + {% endif %} +

    + + {{ message }} + +

    {% endblock %} diff --git a/django/didgeridoo/webshop/urls.py b/django/didgeridoo/webshop/urls.py index 2ae9641..f4958f4 100644 --- a/django/didgeridoo/webshop/urls.py +++ b/django/didgeridoo/webshop/urls.py @@ -23,7 +23,7 @@ urlpatterns = [ url(r'^cart/checkout/$', views.checkout, name='checkout'), - url(r'^order/$', + url(r'^order/(?P[0-9]+)/$', views.order, name='order'), ] diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index c2f363c..fa800a9 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm from django.db import transaction +from decimal import Decimal from webshop.models import (Article, Category, Person, @@ -159,9 +160,32 @@ def article_details(request, article_id): @login_required def profile(request): category_list = get_categories() + totalprice_list = [] + total_list = [] + currency_list = [] + order_list_zip = [] + order_positions_count_list = [] + order_positions_count = "" + total = "" + currency_name = "" person = Person.objects.get(user=request.user) + orders = Order.objects.filter(user=request.user) + if orders: + orders_list = list(orders) + for idx1, order in enumerate(orders_list): + # get all items in the Order: + order_positions = OrderPosition.objects.filter(order=order) + if (order_positions.count()) > 0: + order_positions_count = order_positions.count() + order_positions_count_list.append(order_positions_count) + orders_list[idx1] = order + order_list_zip = zip(orders_list, + order_positions_count_list + ) + # assert False return render(request, 'registration/profile.html', {'person': person, + 'order_list_zip': order_list_zip, 'category_list': category_list}) @@ -222,17 +246,14 @@ def cart(request): if request.method == 'POST': # here we react to a currency dropdown change: if 'currencies' in request.POST: - print('currencies') currencies_form = CurrenciesForm(request.POST) if currencies_form.is_valid(): cf = currencies_form.cleaned_data if cf['currencies']: - print('currencies cf:', cf) selection = cf['currencies'] request.session['currency'] = selection.id currency_name = ExchangeRate_name.objects.get( id=selection.id) - print('currencies currency_name:', currency_name) else: request.session['currency'] = None @@ -375,8 +396,6 @@ def checkout(request): else: order = Order.objects.create(user=request.user, status=orderstatus) - - print('order', order, 'created:', order) for position in cart_positions: OrderPosition.objects.create( article=position.article, @@ -384,7 +403,7 @@ def checkout(request): amount=position.amount, price_in_chf=position.article.price_in_chf ) - return HttpResponseRedirect('/order/') + return HttpResponseRedirect('/order/%s/' % order.id) return render(request, 'webshop/checkout.html', {'cart_position_list': cart_position_list, @@ -394,11 +413,14 @@ def checkout(request): 'article_view': article_view, 'category_list': category_list, 'message': message, - 'person': person + 'person': person, }) -def order(request): +def order(request, order_id): + price_list = [] + totalprice_list = [] + order_position_list_zip = [] cart = ShoppingCart.objects.get(user=request.user) if cart: # get all items in the cart of this customer: @@ -413,5 +435,34 @@ def order(request): ) else: message = """something whent wrong. - We cold not delete your cartitems. """ - return render(request, 'webshop/order.html', {}) + We cold not empty your cart. """ + order = Order.objects.get(id=order_id) + order_positions = OrderPosition.objects.filter(order=order_id) + if (order_positions.count()) > 0: + order_position_list = list(order_positions) + for idx, order_position in enumerate(order_positions): + # get currencyname to display: + if order.exchange_rate is not None: + # get price of position in order and append to a list: + rate = ExchangeRate.objects.get(id=order.exchange_rate.id) + price = round( + rate.exchange_rate_to_chf * order_position.price_in_chf, + 2) + currency_name = order.exchange_rate + else: + currency_name = 'CHF' + price = order_position.price_in_chf + position_price = price * Decimal.from_float(order_position.amount) + order_position_list[idx] = order_position + price_list.append(price) + totalprice_list.append(position_price) + total = sum(totalprice_list) + order_position_list_zip = zip(order_position_list, + price_list, + totalprice_list) + return render(request, 'webshop/order.html', { + 'order': order, + 'order_position_list_zip': order_position_list_zip, + 'total': total, + 'currency_name': currency_name, + })