From eacdbd3f30ddfbe1f6d2a0228b18231002a76239 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 19 Feb 2018 18:39:53 +0100 Subject: [PATCH] push form hack --- django/didgeridoo/webshop/forms.py | 15 +++++++++------ .../webshop/templates/webshop/cart.html | 2 +- django/didgeridoo/webshop/views.py | 11 ++++++----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/django/didgeridoo/webshop/forms.py b/django/didgeridoo/webshop/forms.py index 9c31a3b..925929a 100644 --- a/django/didgeridoo/webshop/forms.py +++ b/django/didgeridoo/webshop/forms.py @@ -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): diff --git a/django/didgeridoo/webshop/templates/webshop/cart.html b/django/didgeridoo/webshop/templates/webshop/cart.html index 334f5a6..78085d4 100644 --- a/django/didgeridoo/webshop/templates/webshop/cart.html +++ b/django/didgeridoo/webshop/templates/webshop/cart.html @@ -25,7 +25,7 @@ {{ cart_position.article.stock }}
- {{ CartForm }} + {{ cart_form }} {% csrf_token %}
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 87becee..9313c73 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -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,