Date: Mon, 26 Feb 2018 21:53:21 +0100
Subject: [PATCH 07/28] display the position amount correctly
---
django/didgeridoo/webshop/templates/webshop/checkout.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/templates/webshop/checkout.html b/django/didgeridoo/webshop/templates/webshop/checkout.html
index f1cad54..2847e82 100644
--- a/django/didgeridoo/webshop/templates/webshop/checkout.html
+++ b/django/didgeridoo/webshop/templates/webshop/checkout.html
@@ -41,7 +41,7 @@
{{ cart_position.article.stock }} |
- {{ cart_position.article.amount }} |
+ {{ cart_position.amount }} |
{{ cart_position.article.price_in_chf }}
{{ currency_name }}
From 3970555cf11dd05fd1be0a1d3843dc8a317cd0c9 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 21:54:11 +0100
Subject: [PATCH 08/28] shorten the line a bit
---
django/didgeridoo/webshop/views.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index f07f88a..077e77e 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -325,7 +325,8 @@ def checkout(request):
request.session['currency'] = None
else:
currency = request.session['currency']
- exchange_rate = ExchangeRate.objects.filter(name=currency).latest('date')
+ exchange_rate = rate.objects.filter(name=currency).latest('date')
+
# Here we handle all POST Operations:
if request.method == 'POST':
print('checkout post', request.POST)
From f62a6a91d9b93dab97f4428492de304194ca52ff Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 21:54:40 +0100
Subject: [PATCH 09/28] only create the order
---
django/didgeridoo/webshop/views.py | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 077e77e..7ef7f69 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -337,15 +337,12 @@ def checkout(request):
if checkout_form.is_valid():
orderstatus = OrderStatus.objects.get(name='ordered')
print('checkout post valid orderstatus', orderstatus,
- 'exchange_rate_id:', exchange_rate_id)
- order, created_order = Order.objects.get_or_create(
- user=request.user,
- defaults={'status': orderstatus,
- 'exchange_rate': exchange_rate,
- }
- )
- print('order', order, 'created:', created_order)
- if created_order is False:
+ '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:
From 494ce666314276681bc09a4a7a483be5fd7c05c5 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 21:55:15 +0100
Subject: [PATCH 10/28] only execute the currency part if it exists in the
session
---
django/didgeridoo/webshop/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 7ef7f69..b962d36 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -362,7 +362,7 @@ def checkout(request):
cart_position_list = list(cart_positions)
# enumerate the list of articles and loop over items:
for idx, cart_position in enumerate(cart_position_list):
- if currency:
+ if request.session['currency']:
# get currencyname to display:
currency_name = ExchangeRate_name.objects.get(id=currency)
# get exchange_rate multiplyed:
From db737eca02ebd25fa39b2cb89a78b72a4a96ae3c Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 21:55:38 +0100
Subject: [PATCH 11/28] only get the cart
the cart was created in the cart view. In the checkout we only want to
display it.
---
django/didgeridoo/webshop/views.py | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index b962d36..8f0a5d6 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -351,12 +351,10 @@ def checkout(request):
# • cancelled -> Bestellung storniert
# • on hold -> Bestellung pausiert
- cart_id, created_cart = ShoppingCart.objects.get_or_create(
- user=request.user)
- if created_cart is False:
+ cart = ShoppingCart.objects.get(user=request.user)
+ if cart:
# get all items in the cart of this customer:
- cart_positions = CartPosition.objects.filter(
- cart=cart_id)
+ cart_positions = CartPosition.objects.filter(cart=cart)
if (cart_positions.count()) > 0:
# make a list out of all articles:
cart_position_list = list(cart_positions)
From d51e9dfa0828aba7111b99bac97136dc65c5d8ca Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 21:56:07 +0100
Subject: [PATCH 12/28] shorten the order view
---
django/didgeridoo/webshop/views.py | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 8f0a5d6..d726a74 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -391,7 +391,4 @@ def checkout(request):
def order(request):
- return render(request, 'webshop/order.html',
- {
-
- })
+ return render(request, 'webshop/order.html', {})
From 45571b8ea94dc15b184eaf8c95a2ec3323bc6129 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:22:22 +0100
Subject: [PATCH 13/28] use CHF as the default currency_name
---
django/didgeridoo/webshop/views.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index d726a74..8fc3c71 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -315,6 +315,7 @@ def checkout(request):
category_list = get_categories()
rate = ExchangeRate
article_view = False
+ currency_name = "CHF"
message = ""
cart_position_list = []
totalprice_list = []
From 6c172405cad3a9a684b9a873c982ae200e676e4a Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:22:45 +0100
Subject: [PATCH 14/28] add the orderposition modell
---
django/didgeridoo/webshop/views.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 8fc3c71..aa9fc4f 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -12,7 +12,8 @@ from webshop.models import (Article,
CartPosition,
ShoppingCart,
Order,
- OrderStatus)
+ OrderStatus,
+ OrderPosition)
from webshop.forms import (RegistrationForm,
AddToCartForm,
CartForm,
From a232ca414c1dcee1289c0617ea994e38b2019923 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:23:15 +0100
Subject: [PATCH 15/28] move the person up
---
django/didgeridoo/webshop/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index aa9fc4f..eb8eb98 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -321,6 +321,7 @@ def checkout(request):
cart_position_list = []
totalprice_list = []
total = 0
+ person = Person.objects.get(user=request.user.id)
checkout_form = CheckoutForm()
if 'currency' not in request.session:
@@ -378,7 +379,6 @@ def checkout(request):
Seams like your cart was
not existent before. How come? """
total = sum(totalprice_list)
- person = Person.objects.get(user=request.user.id)
return render(request, 'webshop/checkout.html',
{'cart_position_list': cart_position_list,
From 865ff557bdefebb4769a03073620283454a6636a Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:23:29 +0100
Subject: [PATCH 16/28] add some empty lines for readability
---
django/didgeridoo/webshop/views.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index eb8eb98..3f91c41 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -374,10 +374,12 @@ def checkout(request):
cart_position.calculate_position_price()
totalprice_list.append(cart_position.position_price)
cart_position_list[idx] = cart_position
+
else:
message = """something whent wrong.
Seams like your cart was
not existent before. How come? """
+
total = sum(totalprice_list)
return render(request, 'webshop/checkout.html',
From b9d2d9f6aea5d3b3bce79338057e8afae5beb90e Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:24:01 +0100
Subject: [PATCH 17/28] only query the exchange_rate if the currency was set
---
django/didgeridoo/webshop/views.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 3f91c41..3cca0d6 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -328,7 +328,6 @@ def checkout(request):
request.session['currency'] = None
else:
currency = request.session['currency']
- exchange_rate = rate.objects.filter(name=currency).latest('date')
# Here we handle all POST Operations:
if request.method == 'POST':
@@ -353,6 +352,8 @@ def checkout(request):
# • delivered -> Bestellung wurde versandt
# • cancelled -> Bestellung storniert
# • on hold -> Bestellung pausiert
+ if currency:
+ exchange_rate = rate.objects.filter(name=currency).latest('date')
cart = ShoppingCart.objects.get(user=request.user)
if cart:
From 9b0fc0ba069669dbdd63529329ad242495f7bf84 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:31:37 +0100
Subject: [PATCH 18/28] allow the ExchangeRate to be null
If we buy the article in CHF there is no ExchangeRate object
---
django/didgeridoo/webshop/models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py
index 33c9106..87b3b4c 100644
--- a/django/didgeridoo/webshop/models.py
+++ b/django/didgeridoo/webshop/models.py
@@ -84,7 +84,7 @@ class Order(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
status = models.ForeignKey(OrderStatus)
date = models.DateTimeField(default=timezone.now)
- exchange_rate = models.ForeignKey(ExchangeRate)
+ exchange_rate = models.ForeignKey(ExchangeRate, null=True)
def __str__(self):
return str(self.id)
From 3073baf43fb21933966fde5761f13d91b68eb10b Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:32:21 +0100
Subject: [PATCH 19/28] remove the person variable
---
django/didgeridoo/webshop/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 3cca0d6..04e4fea 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -180,7 +180,7 @@ def registration(request):
user.last_name = pf['last_name']
user.first_name = pf['first_name']
user.save()
- person = Person.objects.create(
+ Person.objects.create(
salutation=pf['salutation'],
city=City.objects.get(zip_code=pf['zip_code'],
name=pf['city']),
From 29689fd16adccefdcf67f40ccc3435c763f548b9 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:32:46 +0100
Subject: [PATCH 20/28] set the exchange_rate variable to False initially
Since we start with CHF by default the exchange_rate variable should
be False
---
django/didgeridoo/webshop/views.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 04e4fea..8a9b395 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -317,6 +317,7 @@ def checkout(request):
rate = ExchangeRate
article_view = False
currency_name = "CHF"
+ exchange_rate = False
message = ""
cart_position_list = []
totalprice_list = []
From ba61ed12a6363b31ee83bd9936a9234b90cf1a4d Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:33:29 +0100
Subject: [PATCH 21/28] 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,
From ee4d332a3bcac210b02630ca9e8b66efe50d61b1 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:44:36 +0100
Subject: [PATCH 22/28] fix the OrderPosition creation
---
django/didgeridoo/webshop/views.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index 8f9cff4..fa11b38 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -381,10 +381,10 @@ def checkout(request):
print('order', order, 'created:', order)
for position in cart_positions:
OrderPosition.objects.create(
- position.article,
- order,
- position.amount,
- position.article.price_in_chf
+ article=position.article,
+ order=order,
+ amount=position.amount,
+ price_in_chf=position.article.price_in_chf
)
ShoppingCart.objects.delete(pk=cart.id)
From 91d6b2b4d4c6bc3f172382856479b0235d02fadf Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:44:47 +0100
Subject: [PATCH 23/28] fix the cart deletion
---
django/didgeridoo/webshop/views.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py
index fa11b38..ec2ee13 100644
--- a/django/didgeridoo/webshop/views.py
+++ b/django/didgeridoo/webshop/views.py
@@ -386,7 +386,8 @@ def checkout(request):
amount=position.amount,
price_in_chf=position.article.price_in_chf
)
- ShoppingCart.objects.delete(pk=cart.id)
+ cart.delete()
+ cart = False
return render(request, 'webshop/checkout.html',
{'cart_position_list': cart_position_list,
From a1e74a32c2c44e5c1265d2ff2543e617a4cef3d1 Mon Sep 17 00:00:00 2001
From: Andreas Zweili
Date: Mon, 26 Feb 2018 22:51:43 +0100
Subject: [PATCH 24/28] readd the order url
somehow this got lost
---
django/didgeridoo/webshop/templates/webshop/checkout.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/django/didgeridoo/webshop/templates/webshop/checkout.html b/django/didgeridoo/webshop/templates/webshop/checkout.html
index 2847e82..67849ba 100644
--- a/django/didgeridoo/webshop/templates/webshop/checkout.html
+++ b/django/didgeridoo/webshop/templates/webshop/checkout.html
@@ -60,7 +60,7 @@
|
-