|
|
|
|
@ -25,6 +25,31 @@ class RegistrationCartManager: |
|
|
|
|
self.session = request.session |
|
|
|
|
self.first_tournament = False |
|
|
|
|
|
|
|
|
|
def _clean_expired_cart(self): |
|
|
|
|
"""Clean up expired cart data from session""" |
|
|
|
|
if 'registration_cart_expiry' in self.session: |
|
|
|
|
try: |
|
|
|
|
expiry_str = self.session['registration_cart_expiry'] |
|
|
|
|
expiry = datetime.datetime.fromisoformat(expiry_str) |
|
|
|
|
if timezone.now() > expiry: |
|
|
|
|
# Clear expired cart |
|
|
|
|
keys_to_delete = [ |
|
|
|
|
'registration_cart_id', |
|
|
|
|
'registration_tournament_id', |
|
|
|
|
'registration_cart_players', |
|
|
|
|
'registration_cart_expiry', |
|
|
|
|
'registration_mobile_number' |
|
|
|
|
] |
|
|
|
|
for key in keys_to_delete: |
|
|
|
|
if key in self.session: |
|
|
|
|
del self.session[key] |
|
|
|
|
self.session.modified = True |
|
|
|
|
except (ValueError, TypeError): |
|
|
|
|
# Invalid expiry format, clear it |
|
|
|
|
if 'registration_cart_expiry' in self.session: |
|
|
|
|
del self.session['registration_cart_expiry'] |
|
|
|
|
self.session.modified = True |
|
|
|
|
|
|
|
|
|
def get_or_create_cart_id(self): |
|
|
|
|
"""Get or create a registration cart ID in the session""" |
|
|
|
|
if 'registration_cart_id' not in self.session: |
|
|
|
|
@ -50,9 +75,11 @@ class RegistrationCartManager: |
|
|
|
|
try: |
|
|
|
|
expiry = parse_datetime(expiry_str) |
|
|
|
|
if expiry is None: |
|
|
|
|
self._clean_expired_cart() |
|
|
|
|
return True |
|
|
|
|
return timezone.now() > expiry |
|
|
|
|
except (ValueError, TypeError): |
|
|
|
|
self._clean_expired_cart() |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
def reset_cart_expiry(self): |
|
|
|
|
|