add the currency calculation to the article view

This commit is contained in:
Andreas Zweili 2018-01-28 21:26:36 +01:00
parent 915f31c413
commit 6ee5f56e73
2 changed files with 26 additions and 2 deletions

View File

@ -4,8 +4,8 @@
<h3>Description</h3>
<p>{{ article.description }}</p>
<p><b>Stock:</b> {{ article.stock }}</p>
<p><b>Status:</b> {{ article.status}}</p>
<p><b>Price:</b> {{ article.price_in_chf }}</p>
<p><b>Status:</b> {{ article.status }}</p>
<p><b>Price:</b> {{ article.price_in_chf }} {{ currency_name }}</p>
{% for picture in picture_list %}
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
{% endfor %}

View File

@ -104,12 +104,36 @@ def articles_in_category(request, category_id):
def article_details(request, article_id):
category_list = get_categories()
currencies_form = CurrenciesForm
rate=ExchangeRate
article_view = True
currency_name = "CHF"
article = get_object_or_404(Article, pk=article_id)
picture_list = Picture.objects.filter(article=article_id)
if request.method == 'POST':
currencies_form = CurrenciesForm(request.POST)
if currencies_form.is_valid():
cf = currencies_form.cleaned_data
if cf['currencies']:
selection = cf['currencies']
request.session['currency'] = selection.id
currency_name=ExchangeRate_name.objects.get(id=selection.id)
else:
request.session['currency'] = None
if request.session['currency']:
currency = request.session['currency']
article.price_in_chf = rate.exchange(currency, article.price_in_chf)
currency_name=ExchangeRate_name.objects.get(id=currency)
return render(request, 'webshop/article_details.html',
{'article': article,
'category_list': category_list,
'currencies_form': currencies_form,
'article_view': article_view,
'currency_name': currency_name,
'picture_list': picture_list})
@login_required