add the currency calculation to the categories view
This commit is contained in:
parent
0162e10915
commit
915f31c413
|
@ -19,7 +19,7 @@
|
||||||
</a></td>
|
</a></td>
|
||||||
<td scope="col">{{ article.category }}</td>
|
<td scope="col">{{ article.category }}</td>
|
||||||
<td scope="col">{{ article.stock }}</td>
|
<td scope="col">{{ article.stock }}</td>
|
||||||
<td scope="col">{{ article.price_in_chf }}</td>
|
<td scope="col">{{ article.price_in_chf }} {{ currency_name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -67,14 +67,38 @@ def index(request):
|
||||||
def articles_in_category(request, category_id):
|
def articles_in_category(request, category_id):
|
||||||
category_list = get_categories()
|
category_list = get_categories()
|
||||||
selected_category = Category.objects.get(id=category_id)
|
selected_category = Category.objects.get(id=category_id)
|
||||||
|
articles = Article.objects.filter(
|
||||||
articles_list = Article.objects.filter(
|
|
||||||
category=selected_category.id).exclude(status=get_hidden_status_id())
|
category=selected_category.id).exclude(status=get_hidden_status_id())
|
||||||
|
articles_list = list(articles)
|
||||||
|
currencies_form = CurrenciesForm
|
||||||
|
rate=ExchangeRate
|
||||||
|
article_view = True
|
||||||
|
currency_name = "CHF"
|
||||||
|
|
||||||
|
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']
|
||||||
|
for idx, article in enumerate(articles_list):
|
||||||
|
article.price_in_chf = rate.exchange(currency, article.price_in_chf)
|
||||||
|
articles_list[idx] = article
|
||||||
|
currency_name=ExchangeRate_name.objects.get(id=currency)
|
||||||
|
|
||||||
return render(request, 'webshop/category.html',
|
return render(request, 'webshop/category.html',
|
||||||
{'articles_list': articles_list,
|
{'articles_list': articles_list,
|
||||||
'category_list': category_list,
|
'category_list': category_list,
|
||||||
|
'currencies_form': currencies_form,
|
||||||
|
'article_view': article_view,
|
||||||
|
'currency_name': currency_name,
|
||||||
'category': selected_category})
|
'category': selected_category})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue