only display success message if actual extension performed

This commit is contained in:
Mira Weller
2025-05-14 18:20:25 +02:00
parent 87d9f278fb
commit 54a657c8c9
2 changed files with 6 additions and 2 deletions

View File

@@ -294,6 +294,7 @@ class CartManager:
self.invoice_address = invoice_address
self._widget_data = widget_data or {}
self._sales_channel = sales_channel
self.num_extended_positions = 0
if expiry and reservation_time:
raise TypeError('Cannot specify both expiry and reservation_time')
@@ -347,7 +348,7 @@ class CartManager:
# Extend this user's cart session to ensure all items in the cart expire at the same time
# We can extend the reservation of items which are not yet expired without risk
if self._expiry > self.real_now_dt:
self.positions.filter(expires__gt=self.real_now_dt).update(expires=self._expiry)
self.num_extended_positions += self.positions.filter(expires__gt=self.real_now_dt, expires__lt=self._expiry).update(expires=self._expiry)
def _delete_out_of_timeframe(self):
err = None
@@ -606,6 +607,7 @@ class CartManager:
self._voucher_use_diff[cp.voucher] += 2
self._operations.append(op)
self.num_extended_positions += 1
return err
def apply_voucher(self, voucher_code: str):
@@ -1667,6 +1669,7 @@ def extend_cart_reservation(self, event: Event, cart_id: str=None, locale='en',
try:
cm = CartManager(event=event, cart_id=cart_id, sales_channel=sales_channel)
cm.commit()
return cm.num_extended_positions
except LockTimeoutException:
self.retry()
except (MaxRetriesExceededError, LockTimeoutException):

View File

@@ -543,7 +543,8 @@ class CartExtendReservation(EventViewMixin, CartActionMixin, AsyncAction, View):
known_errortypes = ['CartError']
def get_success_message(self, value):
return _('Your cart timeout was extended.')
if value > 0:
return _('Your cart timeout was extended.')
def post(self, request, *args, **kwargs):
return self.do(self.request.event.id, get_or_create_cart_id(self.request), translation.get_language(),