From 9120b019aa290ecabb85aa6fa5dacf4fbbe31350 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 11 Feb 2018 22:37:27 +0100 Subject: [PATCH] remove the solution with the filter --- django/didgeridoo/webshop/templates/webshop/cart.html | 5 +---- django/didgeridoo/webshop/templatetags/cart_filters.py | 7 ------- django/didgeridoo/webshop/views.py | 8 +++----- 3 files changed, 4 insertions(+), 16 deletions(-) delete mode 100644 django/didgeridoo/webshop/templatetags/cart_filters.py diff --git a/django/didgeridoo/webshop/templates/webshop/cart.html b/django/didgeridoo/webshop/templates/webshop/cart.html index 047d6e8..d54c385 100644 --- a/django/didgeridoo/webshop/templates/webshop/cart.html +++ b/django/didgeridoo/webshop/templates/webshop/cart.html @@ -1,5 +1,4 @@ {% extends "webshop/base.html" %} -{% load cart_filters %} {% block section_title %}

Cart

{% endblock %} {% block content %}

List of Items in your Shopping Cart:

@@ -12,8 +11,7 @@ STOCK AMOUNT PRICE p.pce. - PRICE through Model - PRICE through Filter + POSITION PRICE {% for article in articles_list %} @@ -31,7 +29,6 @@ {{ currency_name }} {{ article.position_price }} - {{ totalprice_list|lookup:article.article.id }} {% endfor %} diff --git a/django/didgeridoo/webshop/templatetags/cart_filters.py b/django/didgeridoo/webshop/templatetags/cart_filters.py deleted file mode 100644 index 23494b4..0000000 --- a/django/didgeridoo/webshop/templatetags/cart_filters.py +++ /dev/null @@ -1,7 +0,0 @@ -from django import template - -register = template.Library() - -@register.filter -def lookup(d, key): - return d[key] diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 9c88cdf..8f3a5c6 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -235,7 +235,7 @@ def cart(request): cart_id = False articles_list = "" prices_in_cart = [] - totalprice_list = {} + totalprice_list = [] total = 0 if not 'currency' in request.session: @@ -301,9 +301,7 @@ def cart(request): currency, article.price_in_chf) amount = Decimal.from_float(article.amount) - totalprice_list.update({ - article.article.id:amount * article.article.price_in_chf - }) + totalprice_list.append(article.position_price) articles_list[idx] = article # if cart_id and request.session['currency']: @@ -326,7 +324,7 @@ def cart(request): # for idx, article in enumerate(articles_list): # prices_in_cart.append(article.article.price_in_chf) - total = sum(totalprice_list.values()) + total = sum(totalprice_list) return render(request, 'webshop/cart.html', {'articles_list': articles_list,