diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html index 3c1c3bb..8703063 100644 --- a/django/didgeridoo/webshop/templates/webshop/article_details.html +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -4,8 +4,8 @@

Description

{{ article.description }}

Stock: {{ article.stock }}

-

Status: {{ article.status}}

-

Price: {{ article.price_in_chf }}

+

Status: {{ article.status }}

+

Price: {{ article.price_in_chf }} {{ currency_name }}

{% for picture in picture_list %}

{% endfor %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index f140bd3..ab31203 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -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