push form hack

This commit is contained in:
Andreas Zweili 2018-02-19 18:39:53 +01:00
parent 29e99e49c0
commit eacdbd3f30
3 changed files with 16 additions and 12 deletions

View File

@ -68,16 +68,19 @@ class AddToCartForm(forms.Form):
class CartForm(forms.Form):
print('CartForm')
def ChangeAmount(self, _cart_id, _article_id):
amount_field = forms.IntegerField(
label='pce',
help_text='Enter a Value between 1 and 99.')
def change_amount(self, article):
print('CartForm.ChangeAmount')
article = CartPosition.objects.get(cart=_cart_id, article=_article_id)
amountfield = forms.IntegerField(
position = CartPosition.objects.get(article=article)
self.amount_field = forms.IntegerField(
label='pce',
help_text='Enter a Value between 1 and 99.',
initial=article.amount
initial=position.amount
)
return amountfield
return self.amount_field
class CheckoutForm(forms.Form):

View File

@ -25,7 +25,7 @@
<td scope="col">{{ cart_position.article.stock }}</td>
<td scope="col">
<form id="amountfield" action="" method="POST" novalidate>
{{ CartForm }}
{{ cart_form }}
<input type="submit" value="change" />
{% csrf_token %}
</form>

View File

@ -193,6 +193,7 @@ def registration(request):
def cart(request):
category_list = get_categories()
currencies_form = CurrenciesForm
cart_form = CartForm
rate = ExchangeRate
article_view = True
currency_name = "CHF"
@ -274,12 +275,11 @@ def cart(request):
# get currencyname to display:
currency_name = ExchangeRate_name.objects.get(id=currency)
# get exchange_rate multiplyed:
cart_position.price_in_chf = rate.exchange(
cart_position.article.price_in_chf = rate.exchange(
currency,
article.price_in_chf)
amount = CartForm.ChangeAmount(request.POST,
cart_id,
cart_position.article.id)
cart_position.article.price_in_chf)
amount = cart_form.change_amount(request.POST,
cart_position.article)
totalprice_list.append(cart_position.position_price)
cart_position_list[idx] = cart_position
@ -289,6 +289,7 @@ def cart(request):
{'cart_position_list': cart_position_list,
'totalprice_list': totalprice_list,
'total': total,
'cart_form': cart_form,
'currencies_form': currencies_form,
'checkout_form': checkout_form,
'article_view': article_view,