From ba61ed12a6363b31ee83bd9936a9234b90cf1a4d Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 26 Feb 2018 22:33:29 +0100 Subject: [PATCH] move the post block below the cart operation --- django/didgeridoo/webshop/views.py | 50 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 8a9b395..8f9cff4 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -330,29 +330,6 @@ def checkout(request): else: currency = request.session['currency'] - # Here we handle all POST Operations: - if request.method == 'POST': - print('checkout post', request.POST) - # here we react to a change of amount per item in the Cart: - if 'checkout' in request.POST: - print('checkout post request.POST = checkout_form') - checkout_form = CheckoutForm(request.POST) - if checkout_form.is_valid(): - orderstatus = OrderStatus.objects.get(name='ordered') - print('checkout post valid orderstatus', orderstatus, - 'exchange_rate:', exchange_rate) - order = Order.objects.create(user=request.user, - status=orderstatus, - exchange_rate=exchange_rate) - print('order', order, 'created:', order) - if order is False: - message = """something whent wrong. - Seams like this cart was already submitted. How come? """ - # order status variables: - # • ordered -> vom Kunden bestellt - #  • delivered -> Bestellung wurde versandt - # • cancelled -> Bestellung storniert - # • on hold -> Bestellung pausiert if currency: exchange_rate = rate.objects.filter(name=currency).latest('date') @@ -384,6 +361,33 @@ def checkout(request): total = sum(totalprice_list) + # Here we handle all POST Operations: + if request.method == 'POST': + print('checkout post', request.POST) + # here we react to a change of amount per item in the Cart: + if 'checkout' in request.POST: + print('checkout post request.POST = checkout_form') + checkout_form = CheckoutForm(request.POST) + if checkout_form.is_valid(): + orderstatus = OrderStatus.objects.get(name='ordered') + if exchange_rate: + order = Order.objects.create(user=request.user, + status=orderstatus, + exchange_rate=exchange_rate) + else: + order = Order.objects.create(user=request.user, + status=orderstatus) + + print('order', order, 'created:', order) + for position in cart_positions: + OrderPosition.objects.create( + position.article, + order, + position.amount, + position.article.price_in_chf + ) + ShoppingCart.objects.delete(pk=cart.id) + return render(request, 'webshop/checkout.html', {'cart_position_list': cart_position_list, 'total': total,