remove the solution with the filter

This commit is contained in:
Andreas Zweili 2018-02-11 22:37:27 +01:00
parent 6ef396a6d2
commit 9120b019aa
3 changed files with 4 additions and 16 deletions

View File

@ -1,5 +1,4 @@
{% extends "webshop/base.html" %} {% extends "webshop/base.html" %}
{% load cart_filters %}
{% block section_title %}<h1>Cart</h1>{% endblock %} {% block section_title %}<h1>Cart</h1>{% endblock %}
{% block content %} {% block content %}
<h3>List of Items in your Shopping Cart:</h3> <h3>List of Items in your Shopping Cart:</h3>
@ -12,8 +11,7 @@
<th scope="col">STOCK</th> <th scope="col">STOCK</th>
<th scope="col">AMOUNT</th> <th scope="col">AMOUNT</th>
<th scope="col">PRICE p.pce.</th> <th scope="col">PRICE p.pce.</th>
<th scope="col">PRICE through Model</th> <th scope="col">POSITION PRICE</th>
<th scope="col">PRICE through Filter</th>
</tr> </tr>
{% for article in articles_list %} {% for article in articles_list %}
<tr class="table_content"> <tr class="table_content">
@ -31,7 +29,6 @@
{{ currency_name }} {{ currency_name }}
</td> </td>
<td scope="col">{{ article.position_price }}</td> <td scope="col">{{ article.position_price }}</td>
<td scope="col">{{ totalprice_list|lookup:article.article.id }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr> <tr>

View File

@ -1,7 +0,0 @@
from django import template
register = template.Library()
@register.filter
def lookup(d, key):
return d[key]

View File

@ -235,7 +235,7 @@ def cart(request):
cart_id = False cart_id = False
articles_list = "" articles_list = ""
prices_in_cart = [] prices_in_cart = []
totalprice_list = {} totalprice_list = []
total = 0 total = 0
if not 'currency' in request.session: if not 'currency' in request.session:
@ -301,9 +301,7 @@ def cart(request):
currency, currency,
article.price_in_chf) article.price_in_chf)
amount = Decimal.from_float(article.amount) amount = Decimal.from_float(article.amount)
totalprice_list.update({ totalprice_list.append(article.position_price)
article.article.id:amount * article.article.price_in_chf
})
articles_list[idx] = article articles_list[idx] = article
# if cart_id and request.session['currency']: # if cart_id and request.session['currency']:
@ -326,7 +324,7 @@ def cart(request):
# for idx, article in enumerate(articles_list): # for idx, article in enumerate(articles_list):
# prices_in_cart.append(article.article.price_in_chf) # prices_in_cart.append(article.article.price_in_chf)
total = sum(totalprice_list.values()) total = sum(totalprice_list)
return render(request, 'webshop/cart.html', return render(request, 'webshop/cart.html',
{'articles_list': articles_list, {'articles_list': articles_list,