add a check for the currency session variable

This commit is contained in:
Andreas Zweili 2018-02-04 20:38:54 +01:00
parent b74f3ee585
commit e47156ce2a
1 changed files with 5 additions and 1 deletions

View File

@ -251,15 +251,19 @@ def cart(request):
cart_id = ShoppingCart.objects.get(user=request.user) cart_id = ShoppingCart.objects.get(user=request.user)
except Exception as e: except Exception as e:
message = "You have no items in the Basket" message = "You have no items in the Basket"
if cart_id: if cart_id and request.session['currency']:
articles = CartPosition.objects.filter(cart=cart_id) articles = CartPosition.objects.filter(cart=cart_id)
articles_list = list(articles) articles_list = list(articles)
currency = request.session['currency']
for idx, article in enumerate(articles_list): for idx, article in enumerate(articles_list):
article.price_in_chf = rate.exchange( article.price_in_chf = rate.exchange(
currency, article.article.price_in_chf) currency, article.article.price_in_chf)
articles_list[idx] = article articles_list[idx] = article
currency_name = ExchangeRate_name.objects.get(id=currency) currency_name = ExchangeRate_name.objects.get(id=currency)
article.price_in_chf = rate.exchange(currency, article.price_in_chf) article.price_in_chf = rate.exchange(currency, article.price_in_chf)
else:
articles = CartPosition.objects.filter(cart=cart_id)
articles_list = list(articles)
return render(request, 'webshop/cart.html', return render(request, 'webshop/cart.html',
{'articles_list': articles_list, {'articles_list': articles_list,