add the currency calculation to the article view
This commit is contained in:
parent
915f31c413
commit
6ee5f56e73
|
@ -4,8 +4,8 @@
|
||||||
<h3>Description</h3>
|
<h3>Description</h3>
|
||||||
<p>{{ article.description }}</p>
|
<p>{{ article.description }}</p>
|
||||||
<p><b>Stock:</b> {{ article.stock }}</p>
|
<p><b>Stock:</b> {{ article.stock }}</p>
|
||||||
<p><b>Status:</b> {{ article.status}}</p>
|
<p><b>Status:</b> {{ article.status }}</p>
|
||||||
<p><b>Price:</b> {{ article.price_in_chf }}</p>
|
<p><b>Price:</b> {{ article.price_in_chf }} {{ currency_name }}</p>
|
||||||
{% for picture in picture_list %}
|
{% for picture in picture_list %}
|
||||||
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
|
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -104,12 +104,36 @@ def articles_in_category(request, category_id):
|
||||||
|
|
||||||
def article_details(request, article_id):
|
def article_details(request, article_id):
|
||||||
category_list = get_categories()
|
category_list = get_categories()
|
||||||
|
currencies_form = CurrenciesForm
|
||||||
|
rate=ExchangeRate
|
||||||
|
article_view = True
|
||||||
|
currency_name = "CHF"
|
||||||
|
|
||||||
article = get_object_or_404(Article, pk=article_id)
|
article = get_object_or_404(Article, pk=article_id)
|
||||||
picture_list = Picture.objects.filter(article=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',
|
return render(request, 'webshop/article_details.html',
|
||||||
{'article': article,
|
{'article': article,
|
||||||
'category_list': category_list,
|
'category_list': category_list,
|
||||||
|
'currencies_form': currencies_form,
|
||||||
|
'article_view': article_view,
|
||||||
|
'currency_name': currency_name,
|
||||||
'picture_list': picture_list})
|
'picture_list': picture_list})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
Loading…
Reference in New Issue