From 84dadd9147c256daf5c8ff3bbe5667c874e35a79 Mon Sep 17 00:00:00 2001 From: mobilinux Date: Sat, 31 Aug 2024 22:02:09 +0200 Subject: [PATCH] Prevent inintended creation of OrderAuthor before ordering When a grouped_order_detail view was called with authenticated user, when prefilling the firstName, lastName and email also inserted a new OrderAuthor object in the database. Now use SimpleNamespace, instead of OrderAuthor object, to carry those values to the template. --- la_chariotte/order/views/grouped_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/la_chariotte/order/views/grouped_order.py b/la_chariotte/order/views/grouped_order.py index f2c454b..5f24fc3 100644 --- a/la_chariotte/order/views/grouped_order.py +++ b/la_chariotte/order/views/grouped_order.py @@ -1,5 +1,6 @@ import csv import json +from types import SimpleNamespace from django import http from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin @@ -118,12 +119,11 @@ class GroupedOrderDetailView(generic.DetailView): prices_dict = {item.id: item.price for item in items} if self.request.user.is_authenticated: - order_author = OrderAuthor.objects.create( + order_author = SimpleNamespace( first_name=self.request.user.first_name, last_name=self.request.user.last_name, email=self.request.user.username, ) - order_author.save() else: order_author = None