From a8a27c6b75b4972ff07cb96a71b9c5919332b82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Tue, 27 Feb 2018 20:46:05 +0100 Subject: [PATCH 01/15] add profile view of orders --- .../templates/registration/profile.html | 28 ++++++++ django/didgeridoo/webshop/views.py | 64 ++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/django/didgeridoo/webshop/templates/registration/profile.html b/django/didgeridoo/webshop/templates/registration/profile.html index ed2e406..a09da87 100644 --- a/django/didgeridoo/webshop/templates/registration/profile.html +++ b/django/didgeridoo/webshop/templates/registration/profile.html @@ -3,6 +3,7 @@ {% block section_title %}User Profile{% endblock %} {% block content %} +

Username: {{ request.user.username }}

Salutation: {{ person.salutation }}

Firstname: {{ request.user.first_name }}

@@ -14,4 +15,31 @@ {% csrf_token %} {{ form.as_p }} +{% if order_list_zip %} +
+

Orders:

+ + + + + + + + + {% for order, order_positions_count, total, currency_name in order_list_zip %} + + + + + + + +
IDDATESTATUSITEMSPRICE
{{ order.id }}{{ order.date }}{{ order.status }}{{ order_positions_count }}{{ total }} {{ currency_name }}
+{% endfor %} +{% 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/views.py b/django/didgeridoo/webshop/views.py index 604d9d8..8a8f018 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -159,9 +159,48 @@ 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) + orders_list = list(orders) + for idx1, order in enumerate(orders_list): + currency = order.exchange_rate + print('order:', order, 'currency:', currency) + # get all items in the Order: + order_positions = OrderPosition.objects.get(order=order) + if (order_positions.count()) > 0: + order_position_list = list(order_positions) + print('order_position_list:', order_position_list) + for idx2, order_position in enumerate(order_position_list): + # get currencyname to display: + currency_name = ExchangeRate_name.objects.get(id=currency) + # get exchange_rate multiplyed: + order_position.article.price_in_chf = ExchangeRate.exchange( + currency, + order_position.article.price_in_chf + ) + # get price of position in order and append to a summed list: + order_position.calculate_position_price() + totalprice_list.append(order_position.position_price) + order_position_list[idx2] = order_position + currency_list.append(currency_name) + total = sum(totalprice_list) + total_list.append(total) + 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, total, currency_name) + assert False return render(request, 'registration/profile.html', {'person': person, + 'order_list_zip': order_list_zip, 'category_list': category_list}) @@ -416,5 +455,28 @@ def order(request): ) else: message = """something whent wrong. - We cold not delete your cartitems. """ + We cold not empty your cart. """ + + # category_list = get_categories() + # person = Person.objects.get(user=request.user) + # orders = Order.objects.filter(user=request.user) + # for order in orders: + # currency = order.exchange_rate + # # get all items in the Order: + # order_positions = OrderPosition.objects.filter(order=order) + # if (order_positions.count()) > 0: + # order_position_list = list(order_positions) + # for idx, order_position in enumerate(order_position_list): + # # get currencyname to display: + # currency_name = ExchangeRate_name.objects.get(id=currency) + # # get exchange_rate multiplyed: + # cart_position.article.price_in_chf = ExchangeRate.exchange( + # currency, + # order_position.article.price_in_chf + # ) + # order_position.calculate_position_price() + # totalprice_list.append(order_position.position_price) + # order_position_list[idx] = order_position + # + # total = sum(totalprice_list) return render(request, 'webshop/order.html', {}) From f6ae6cf872f06717d8372dfdbc4568d0557e2084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Tue, 27 Feb 2018 22:01:39 +0100 Subject: [PATCH 02/15] add profile oders in tableform with --- django/didgeridoo/rss | 1242 ++++++++--------- django/didgeridoo/webshop/models.py | 4 + .../templates/registration/profile.html | 2 +- django/didgeridoo/webshop/views.py | 34 +- 4 files changed, 644 insertions(+), 638 deletions(-) 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/webshop/models.py b/django/didgeridoo/webshop/models.py index 87b3b4c..27bcdba 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -100,6 +100,10 @@ class OrderPosition(models.Model): validators=[MinValueValidator( Decimal('0.00'))]) + def calculate_position_price(self): + decimal_amount = Decimal.from_float(self.amount) + self.position_price = decimal_amount * self.article.price_in_chf + class ShoppingCart(models.Model): """ Cart to User Relationships """ diff --git a/django/didgeridoo/webshop/templates/registration/profile.html b/django/didgeridoo/webshop/templates/registration/profile.html index a09da87..5a7a74d 100644 --- a/django/didgeridoo/webshop/templates/registration/profile.html +++ b/django/didgeridoo/webshop/templates/registration/profile.html @@ -34,8 +34,8 @@ {{ order_positions_count }} {{ total }} {{ currency_name }} + {% endfor %} -{% endfor %} {% else %}

you don't have Ordered anything yet. diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 700fd23..f873d97 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -171,33 +171,35 @@ def profile(request): orders = Order.objects.filter(user=request.user) orders_list = list(orders) for idx1, order in enumerate(orders_list): - currency = order.exchange_rate - print('order:', order, 'currency:', currency) # get all items in the Order: - order_positions = OrderPosition.objects.get(order=order) + order_positions = OrderPosition.objects.filter(order=order) if (order_positions.count()) > 0: order_position_list = list(order_positions) - print('order_position_list:', order_position_list) for idx2, order_position in enumerate(order_position_list): # get currencyname to display: - currency_name = ExchangeRate_name.objects.get(id=currency) - # get exchange_rate multiplyed: - order_position.article.price_in_chf = ExchangeRate.exchange( - currency, - order_position.article.price_in_chf - ) - # get price of position in order and append to a summed list: - order_position.calculate_position_price() - totalprice_list.append(order_position.position_price) + if order.exchange_rate is not None: + print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id) + # get price of position in order and append to a list: + rate = ExchangeRate.objects.get(id=order.exchange_rate.id) + order_position.price_in_chf = round( + rate.exchange_rate_to_chf * order_position.price_in_chf, + 2) + currency_name = order.exchange_rate + else: + currency_name = 'CHF' + totalprice_list.append(order_position.price_in_chf) order_position_list[idx2] = order_position + total = sum(totalprice_list) currency_list.append(currency_name) - total = sum(totalprice_list) total_list.append(total) 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, total, currency_name) - assert False + order_list_zip = zip(orders_list, + order_positions_count_list, + total_list, + currency_list) + # assert False return render(request, 'registration/profile.html', {'person': person, 'order_list_zip': order_list_zip, From 9354817dd7113c32983d5cd8b68be01cbcdc4bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Tue, 27 Feb 2018 22:11:02 +0100 Subject: [PATCH 03/15] fix excepton if user has no orders. --- django/didgeridoo/webshop/views.py | 61 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index f873d97..42df889 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -169,36 +169,37 @@ def profile(request): currency_name = "" person = Person.objects.get(user=request.user) orders = Order.objects.filter(user=request.user) - 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_position_list = list(order_positions) - for idx2, order_position in enumerate(order_position_list): - # get currencyname to display: - if order.exchange_rate is not None: - print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id) - # get price of position in order and append to a list: - rate = ExchangeRate.objects.get(id=order.exchange_rate.id) - order_position.price_in_chf = round( - rate.exchange_rate_to_chf * order_position.price_in_chf, - 2) - currency_name = order.exchange_rate - else: - currency_name = 'CHF' - totalprice_list.append(order_position.price_in_chf) - order_position_list[idx2] = order_position - total = sum(totalprice_list) - currency_list.append(currency_name) - total_list.append(total) - 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, - total_list, - currency_list) + 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_position_list = list(order_positions) + for idx2, order_position in enumerate(order_position_list): + # get currencyname to display: + if order.exchange_rate is not None: + print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id) + # get price of position in order and append to a list: + rate = ExchangeRate.objects.get(id=order.exchange_rate.id) + order_position.price_in_chf = round( + rate.exchange_rate_to_chf * order_position.price_in_chf, + 2) + currency_name = order.exchange_rate + else: + currency_name = 'CHF' + totalprice_list.append(order_position.price_in_chf) + order_position_list[idx2] = order_position + total = sum(totalprice_list) + currency_list.append(currency_name) + total_list.append(total) + 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, + total_list, + currency_list) # assert False return render(request, 'registration/profile.html', {'person': person, From f170f5b0daa5ac170a3cf7cc77a59ffaca9ce2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Tue, 27 Feb 2018 22:16:24 +0100 Subject: [PATCH 04/15] add checkout cancel button --- django/didgeridoo/webshop/templates/webshop/checkout.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/django/didgeridoo/webshop/templates/webshop/checkout.html b/django/didgeridoo/webshop/templates/webshop/checkout.html index ad9c9ff..f8e32b3 100644 --- a/django/didgeridoo/webshop/templates/webshop/checkout.html +++ b/django/didgeridoo/webshop/templates/webshop/checkout.html @@ -60,6 +60,11 @@ +

+ {% csrf_token %} + +
+
{% csrf_token %} {{ checkout_form.as_p }} From a18765b0a663a943b1ded4014cbec6b7550fa091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Tue, 27 Feb 2018 23:56:41 +0100 Subject: [PATCH 05/15] add orders RESTfull --- .../templates/registration/profile.html | 16 +++-- .../webshop/templates/webshop/order.html | 53 +++++++++++++++ django/didgeridoo/webshop/urls.py | 2 +- django/didgeridoo/webshop/views.py | 66 ++++++++++--------- 4 files changed, 98 insertions(+), 39 deletions(-) diff --git a/django/didgeridoo/webshop/templates/registration/profile.html b/django/didgeridoo/webshop/templates/registration/profile.html index 5a7a74d..c5b2075 100644 --- a/django/didgeridoo/webshop/templates/registration/profile.html +++ b/django/didgeridoo/webshop/templates/registration/profile.html @@ -27,13 +27,15 @@ PRICE {% for order, order_positions_count, total, currency_name in order_list_zip %} - - {{ order.id }} - {{ order.date }} - {{ order.status }} - {{ order_positions_count }} - {{ total }} {{ currency_name }} - + + {{ order.id }} + {{ order.date }} + + {{ order.status }} + + {{ order_positions_count }} + {{ total }} {{ currency_name }} + {% endfor %} {% else %} diff --git a/django/didgeridoo/webshop/templates/webshop/order.html b/django/didgeridoo/webshop/templates/webshop/order.html index 1ffcde5..706671b 100644 --- a/django/didgeridoo/webshop/templates/webshop/order.html +++ b/django/didgeridoo/webshop/templates/webshop/order.html @@ -4,4 +4,57 @@ {% block content %}

Your order was submitted.

Thank you for Purchase.

+

List of Items in your Shopping Cart:

+ {% if order_position_list %} + + + + + + + + + + + {% for order_position in order_position_list %} + + + + + + + + + + {% 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 }} + {{ order_position.article.price_in_chf }} + {{ currency_name }} + + {{ order_position.position_price }} {{ currency_name }} +
+ +
Total:
+
{{ total }} {{ currency_name }}
+
+ {% 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 42df889..7bc3165 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, @@ -172,6 +173,7 @@ def profile(request): if orders: orders_list = list(orders) for idx1, order in enumerate(orders_list): + print(order.id) # get all items in the Order: order_positions = OrderPosition.objects.filter(order=order) if (order_positions.count()) > 0: @@ -192,8 +194,8 @@ def profile(request): order_position_list[idx2] = order_position total = sum(totalprice_list) currency_list.append(currency_name) - total_list.append(total) - order_positions_count = order_positions.count() + total_list.append(total) + order_positions_count = order_positions.count() order_positions_count_list.append(order_positions_count) orders_list[idx1] = order order_list_zip = zip(orders_list, @@ -417,8 +419,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, @@ -426,7 +426,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, @@ -436,11 +436,13 @@ 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): + totalprice_list = [] + order_position_list = [] cart = ShoppingCart.objects.get(user=request.user) if cart: # get all items in the cart of this customer: @@ -456,27 +458,29 @@ def order(request): else: message = """something whent wrong. We cold not empty your cart. """ - - # category_list = get_categories() - # person = Person.objects.get(user=request.user) - # orders = Order.objects.filter(user=request.user) - # for order in orders: - # currency = order.exchange_rate - # # get all items in the Order: - # order_positions = OrderPosition.objects.filter(order=order) - # if (order_positions.count()) > 0: - # order_position_list = list(order_positions) - # for idx, order_position in enumerate(order_position_list): - # # get currencyname to display: - # currency_name = ExchangeRate_name.objects.get(id=currency) - # # get exchange_rate multiplyed: - # cart_position.article.price_in_chf = ExchangeRate.exchange( - # currency, - # order_position.article.price_in_chf - # ) - # order_position.calculate_position_price() - # totalprice_list.append(order_position.position_price) - # order_position_list[idx] = order_position - # - # total = sum(totalprice_list) - return render(request, 'webshop/order.html', {}) + 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: + print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id) + # get price of position in order and append to a list: + rate = ExchangeRate.objects.get(id=order.exchange_rate.id) + order_position.price = round( + rate.exchange_rate_to_chf * order_position.price_in_chf, + 2) + currency_name = order.exchange_rate + else: + currency_name = 'CHF' + order_position.price = order_position.price_in_chf + order_position.position_price = order_position.price * Decimal.from_float(order_position.amount) + order_position_list[idx] = order_position + totalprice_list.append(order_position.price) + total = sum(totalprice_list) + return render(request, 'webshop/order.html', { + 'order_position_list': order_position_list, + 'currency_name': currency_name, + 'total': total + }) From f8a6932bdebf317d3cd4aeb87514057c5a68a069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 00:30:02 +0100 Subject: [PATCH 06/15] delete unneaded line --- django/didgeridoo/currencies/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index b49ae44..52d8aed 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) From ab30417a8016451fc10abeef3c93622d2fadf101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 01:22:27 +0100 Subject: [PATCH 07/15] cleanup --- .../didgeridoo/currencies/exchange_rates.py | 3 +- .../templates/currencies/index.html | 2 +- django/didgeridoo/currencies/urls.py | 5 +--- django/didgeridoo/currencies/views.py | 14 --------- django/didgeridoo/static/js/app.js | 30 ------------------- .../webshop/templates/webshop/base.html | 1 - 6 files changed, 3 insertions(+), 52 deletions(-) delete mode 100644 django/didgeridoo/static/js/app.js 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/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index 2f28ccb..acd63fb 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -1,7 +1,7 @@ {% extends "webshop/base.html" %} {% block section_title %}Currencies in CHF{% endblock %} {% block content %} -

{{ message }}

+
{{ message }}

Frühere Daten:

US Dollars:

{% if currency_USD_list %} 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 52d8aed..62de99a 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -7,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 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 - From 1e577f4520bb4b5a35ee56bb4226891946d8cb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 01:23:20 +0100 Subject: [PATCH 08/15] improve dropdown --- django/didgeridoo/currencies/forms.py | 11 ++++++++++- django/didgeridoo/webshop/templates/webshop/nav.html | 3 +-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 02259d9..0464a86 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -5,4 +5,13 @@ from currencies.models import 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/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index 6390f7b..fac5436 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -13,11 +13,10 @@ {% else %}
  • LOGIN
  • {% endif %} -
  • {% if article_view %} {{ currencies_form.as_ul }} -
  • {% csrf_token %} {% endif %} From db1fb337ba129ebce52658a83da6f6cb851b2d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 08:13:13 +0100 Subject: [PATCH 09/15] cleanup code and refacture visual usability --- .../templates/registration/profile.html | 10 ++--- .../webshop/templates/webshop/order.html | 23 ++++++++--- django/didgeridoo/webshop/views.py | 38 +++++++++---------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/django/didgeridoo/webshop/templates/registration/profile.html b/django/didgeridoo/webshop/templates/registration/profile.html index c5b2075..787540b 100644 --- a/django/didgeridoo/webshop/templates/registration/profile.html +++ b/django/didgeridoo/webshop/templates/registration/profile.html @@ -5,12 +5,12 @@ {% block content %}

    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 }} diff --git a/django/didgeridoo/webshop/templates/webshop/order.html b/django/didgeridoo/webshop/templates/webshop/order.html index 706671b..16f7cd0 100644 --- a/django/didgeridoo/webshop/templates/webshop/order.html +++ b/django/didgeridoo/webshop/templates/webshop/order.html @@ -2,10 +2,20 @@ {% load customfilters %} {% block section_title %}Order{% endblock %} {% block content %} -

    Your order was submitted.

    -

    Thank you for Purchase.

    -

    List of Items in your Shopping Cart:

    - {% if order_position_list %} + {% 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 %} @@ -16,7 +26,7 @@ - {% for order_position in order_position_list %} + {% for order_position, price in order_position_list_zip %} @@ -32,7 +42,7 @@ {{ currency_name }} {% endfor %} @@ -45,6 +55,7 @@
    POS.PRICE p.pce. POSITION PRICE
    {{ order_position.id }} {{ order_position.article.id }} - {{ order_position.position_price }} {{ currency_name }} + {{ price }} {{ currency_name }}
    +

    Thank you for Purchase.

    {% else %}

    diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 7bc3165..6382ede 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -173,30 +173,30 @@ def profile(request): if orders: orders_list = list(orders) for idx1, order in enumerate(orders_list): - print(order.id) # 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_position_list = list(order_positions) for idx2, order_position in enumerate(order_position_list): # get currencyname to display: if order.exchange_rate is not None: - print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id) # get price of position in order and append to a list: - rate = ExchangeRate.objects.get(id=order.exchange_rate.id) + rate = ExchangeRate.objects.get( + id=order.exchange_rate.id) order_position.price_in_chf = round( - rate.exchange_rate_to_chf * order_position.price_in_chf, + rate.exchange_rate_to_chf * + order_position.price_in_chf, 2) currency_name = order.exchange_rate else: currency_name = 'CHF' totalprice_list.append(order_position.price_in_chf) order_position_list[idx2] = order_position - total = sum(totalprice_list) + total = sum(totalprice_list) currency_list.append(currency_name) - total_list.append(total) - order_positions_count = order_positions.count() - order_positions_count_list.append(order_positions_count) + total_list.append(total) + order_positions_count_list.append(order_positions_count) orders_list[idx1] = order order_list_zip = zip(orders_list, order_positions_count_list, @@ -266,17 +266,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 @@ -441,8 +438,9 @@ def checkout(request): def order(request, order_id): + price_list = [] totalprice_list = [] - order_position_list = [] + order_position_list_zip = [] cart = ShoppingCart.objects.get(user=request.user) if cart: # get all items in the cart of this customer: @@ -465,22 +463,24 @@ def order(request, order_id): for idx, order_position in enumerate(order_positions): # get currencyname to display: if order.exchange_rate is not None: - print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id) # get price of position in order and append to a list: rate = ExchangeRate.objects.get(id=order.exchange_rate.id) - order_position.price = round( + price = round( rate.exchange_rate_to_chf * order_position.price_in_chf, 2) currency_name = order.exchange_rate else: currency_name = 'CHF' - order_position.price = order_position.price_in_chf - order_position.position_price = order_position.price * Decimal.from_float(order_position.amount) + price = order_position.price_in_chf + position_price = price * Decimal.from_float(order_position.amount) order_position_list[idx] = order_position - totalprice_list.append(order_position.price) + price_list.append(price) + totalprice_list.append(position_price) total = sum(totalprice_list) + order_position_list_zip = zip(order_position_list, price_list) return render(request, 'webshop/order.html', { - 'order_position_list': order_position_list, + 'order': order, + 'order_position_list_zip': order_position_list_zip, + 'total': total, 'currency_name': currency_name, - 'total': total }) From 3a8a5ea1dad9a2532b510986799983c2b57310cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 21:05:27 +0100 Subject: [PATCH 10/15] refactor and clean --- django/didgeridoo/currencies/forms.py | 2 +- .../templates/currencies/index.html | 78 +++---------------- .../currencies/templatetags/customfilters.py | 12 --- django/didgeridoo/currencies/views.py | 25 ++---- .../templates/webshop/article_details.html | 4 +- .../webshop/templates/webshop/index.html | 1 - 6 files changed, 20 insertions(+), 102 deletions(-) delete mode 100644 django/didgeridoo/currencies/templatetags/customfilters.py diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 0464a86..29e2cc2 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -1,5 +1,5 @@ from django import forms -from currencies.models import ExchangeRate_name +from currencies.models import ExchangeRate, ExchangeRate_name class CurrenciesForm(forms.Form): diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index acd63fb..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/views.py b/django/didgeridoo/currencies/views.py index 62de99a..4a5ac1f 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -42,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) @@ -148,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/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/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 %} From 404941b235781b231f1dd123171d76542303efa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 21:40:17 +0100 Subject: [PATCH 11/15] fix pos_price in Orderview --- django/didgeridoo/webshop/templates/webshop/order.html | 5 ++--- django/didgeridoo/webshop/views.py | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/django/didgeridoo/webshop/templates/webshop/order.html b/django/didgeridoo/webshop/templates/webshop/order.html index 16f7cd0..6f0ab0b 100644 --- a/django/didgeridoo/webshop/templates/webshop/order.html +++ b/django/didgeridoo/webshop/templates/webshop/order.html @@ -1,5 +1,4 @@ {% extends "webshop/base.html" %} -{% load customfilters %} {% block section_title %}Order{% endblock %} {% block content %} {% if order %} @@ -26,7 +25,7 @@ PRICE p.pce. POSITION PRICE - {% for order_position, price in order_position_list_zip %} + {% for order_position, price, pos_price in order_position_list_zip %} {{ order_position.id }} {{ order_position.article.id }} @@ -42,7 +41,7 @@ {{ currency_name }} - {{ price }} {{ currency_name }} + {{ pos_price }} {{ currency_name }} {% endfor %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 6382ede..32470d5 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -477,7 +477,9 @@ def order(request, order_id): price_list.append(price) totalprice_list.append(position_price) total = sum(totalprice_list) - order_position_list_zip = zip(order_position_list, price_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, From de2426433179fb9e9e02c991e8a4126a777f07d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 21:47:19 +0100 Subject: [PATCH 12/15] undo currency dropdown onclick and fix price tag in order --- django/didgeridoo/currencies/forms.py | 12 ++++++------ django/didgeridoo/webshop/templates/webshop/nav.html | 3 ++- .../didgeridoo/webshop/templates/webshop/order.html | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 29e2cc2..6dc1071 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -8,10 +8,10 @@ class CurrenciesForm(forms.Form): required=False, empty_label='CHF', label='CURENCIES', - widget=forms.Select( - attrs={ - 'onchange': 'currency.submit();', - 'class': 'btn-primary dropdown-toggle' - } - ) + # widget=forms.Select( + # attrs={ + # 'onchange': 'currency.submit();', + # 'class': 'btn-primary dropdown-toggle' + # } + #) ) diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index fac5436..3800432 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -17,7 +17,8 @@ {% 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 6f0ab0b..301f7aa 100644 --- a/django/didgeridoo/webshop/templates/webshop/order.html +++ b/django/didgeridoo/webshop/templates/webshop/order.html @@ -37,7 +37,7 @@ {{ order_position.article.stock }} {{ order_position.amount }} - {{ order_position.article.price_in_chf }} + {{ price }} {{ currency_name }} From fc2af695a2ecbe99b962131474f99f8ddc33637b Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 28 Feb 2018 21:58:18 +0100 Subject: [PATCH 13/15] add a link to the Readme --- django/didgeridoo/webshop/templates/webshop/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index e4a6c85..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
  • From 2704848368c601e4ec72e1f035cf38f9f5302a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 22:19:43 +0100 Subject: [PATCH 14/15] for history --- django/didgeridoo/webshop/views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 32470d5..be85bac 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -179,25 +179,30 @@ def profile(request): order_positions_count = order_positions.count() order_position_list = list(order_positions) for idx2, order_position in enumerate(order_position_list): + position_price = None + price = None # 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) - order_position.price_in_chf = round( + price = round( rate.exchange_rate_to_chf * order_position.price_in_chf, 2) currency_name = order.exchange_rate else: currency_name = 'CHF' - totalprice_list.append(order_position.price_in_chf) + price = order_position.price_in_chf + position_price = price * Decimal.from_float( + order_position.amount) + totalprice_list.append(position_price) order_position_list[idx2] = order_position total = sum(totalprice_list) currency_list.append(currency_name) total_list.append(total) order_positions_count_list.append(order_positions_count) - orders_list[idx1] = order + orders_list[idx1] = order order_list_zip = zip(orders_list, order_positions_count_list, total_list, From 51c5affa85100394f4348a852a23ba5e6a906ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 22:22:28 +0100 Subject: [PATCH 15/15] delete total of order in profile view --- .../templates/registration/profile.html | 6 +--- django/didgeridoo/webshop/views.py | 29 ++----------------- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/django/didgeridoo/webshop/templates/registration/profile.html b/django/didgeridoo/webshop/templates/registration/profile.html index 787540b..864795e 100644 --- a/django/didgeridoo/webshop/templates/registration/profile.html +++ b/django/didgeridoo/webshop/templates/registration/profile.html @@ -23,18 +23,14 @@ ID DATE STATUS - ITEMS - PRICE - {% for order, order_positions_count, total, currency_name in order_list_zip %} + {% for order, order_positions_count in order_list_zip %} {{ order.id }} {{ order.date }} {{ order.status }} - {{ order_positions_count }} - {{ total }} {{ currency_name }} {% endfor %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index be85bac..fa800a9 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -177,36 +177,11 @@ def profile(request): order_positions = OrderPosition.objects.filter(order=order) if (order_positions.count()) > 0: order_positions_count = order_positions.count() - order_position_list = list(order_positions) - for idx2, order_position in enumerate(order_position_list): - position_price = None - price = None - # 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) - totalprice_list.append(position_price) - order_position_list[idx2] = order_position - total = sum(totalprice_list) - currency_list.append(currency_name) - total_list.append(total) order_positions_count_list.append(order_positions_count) orders_list[idx1] = order order_list_zip = zip(orders_list, - order_positions_count_list, - total_list, - currency_list) + order_positions_count_list + ) # assert False return render(request, 'registration/profile.html', {'person': person,