From 174e96402e8ebfaafbbc232fb91cd14aa8b9e712 Mon Sep 17 00:00:00 2001 From: Raz Date: Thu, 17 Apr 2025 14:50:34 +0200 Subject: [PATCH] fix settings online payment --- api/views.py | 4 +- padelclub_backend/settings_local.py.dist | 49 +++++++++--------------- tournaments/models/tournament.py | 17 ++++---- 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/api/views.py b/api/views.py index d13ee9f..be20311 100644 --- a/api/views.py +++ b/api/views.py @@ -413,12 +413,12 @@ def xls_to_csv(request): @permission_classes([IsAuthenticated]) def get_tournament_config(request): """Return tournament-related configuration settings""" - config = settings.TOURNAMENT_SETTINGS['TIME_TO_CONFIRM'] + config = settings.TOURNAMENT_SETTINGS return Response({ 'time_proximity_rules': config['TIME_PROXIMITY_RULES'], 'waiting_list_rules': config['WAITING_LIST_RULES'], 'business_rules': config['BUSINESS_RULES'], - 'urgency_override': config['URGENCY_OVERRIDE'] + 'minimum_response_time': config['MINIMUM_RESPONSE_TIME'] }) @api_view(['GET']) diff --git a/padelclub_backend/settings_local.py.dist b/padelclub_backend/settings_local.py.dist index 2254cc3..f983539 100644 --- a/padelclub_backend/settings_local.py.dist +++ b/padelclub_backend/settings_local.py.dist @@ -44,38 +44,25 @@ SHOP_STRIPE_WEBHOOK_SECRET = 'whsec_...' # Your existing webhook secret TOURNAMENT_STRIPE_WEBHOOK_SECRET = 'whsec_...' # New webhook secret for tournaments STRIPE_FEE = 0.0075 TOURNAMENT_SETTINGS = { - 'TIME_TO_CONFIRM': { - 'TIME_PROXIMITY_RULES': { - 24: 30, # within 24h → 30 min - 48: 60, # within 48h → 60 min - 72: 120, # within 72h → 120 min - 'default': 240 - }, - 'WAITING_LIST_RULES': { - 30: 30, # 30+ teams → 30 min - 20: 60, # 20+ teams → 60 min - 10: 120, # 10+ teams → 120 min - 'default': 240 - }, - 'BUSINESS_RULES': { - 'hours': { - 'start': 8, # 8:00 - 'end': 21, # 21:00 - 'default_confirmation_hour': 8 # When extending to next day - }, - 'days': { - 'working_days': [0, 1, 2, 3, 4, 5, 6], # Monday = 0, Friday = 4 - 'weekend': [] # Saturday = 5, Sunday = 6 - } - }, - 'URGENCY_OVERRIDE': { - 'thresholds': { - 24: True, # If ≤ 24h until tournament: ignore business hours - 12: True # If ≤ 12h until tournament: ignore all restrictions - }, - 'minimum_response_time': 30 # minutes + 'TIME_PROXIMITY_RULES': { + 24: 30, # within 24h → 30 min + 48: 60, # within 48h → 60 min + 72: 120, # within 72h → 120 min + 'default': 240 + }, + 'WAITING_LIST_RULES': { + 30: 30, # 30+ teams → 30 min + 20: 60, # 20+ teams → 60 min + 10: 120, # 10+ teams → 120 min + 'default': 240 + }, + 'BUSINESS_RULES': { + 'hours': { + 'start': 8, # 8:00 + 'end': 21, # 21:00 } - } + }, + 'MINIMUM_RESPONSE_TIME': 30, # requires to be like the BACKGROUND_SCHEDULED_TASK_INTERVAL } BACKGROUND_SCHEDULED_TASK_INTERVAL = 30 # minutes diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 0042a78..808e0e1 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1540,11 +1540,10 @@ class Tournament(BaseModel): if self.automatic_waiting_list() is False: return None - config = settings.TOURNAMENT_SETTINGS['TIME_TO_CONFIRM'] + config = settings.TOURNAMENT_SETTINGS TIME_PROXIMITY_RULES = config['TIME_PROXIMITY_RULES'] WAITING_LIST_RULES = config['WAITING_LIST_RULES'] BUSINESS_RULES = config['BUSINESS_RULES'] - URGENCY_OVERRIDE = config['URGENCY_OVERRIDE'] # 1. Get current time in tournament's timezone current_time = timezone.now() @@ -1579,11 +1578,6 @@ class Tournament(BaseModel): # 6. Use the more restrictive rule (smaller time window) minutes_to_confirm = min(time_based_minutes, waitlist_based_minutes) - live_testing = getattr(settings, 'LIVE_TESTING', False) - # Divide by 10 if LIVE_TESTING is enabled - if live_testing: - minutes_to_confirm = minutes_to_confirm / 10 - # 7. Check urgency overrides apply_business_rules = True @@ -1605,11 +1599,18 @@ class Tournament(BaseModel): # 24 hours before tournament: 7am - 10pm business_start_hour = 7 business_end_hour = 22 + minutes_to_confirm = config.MINIMUM_RESPONSE_TIME if hours_until_tournament <= 12: # 12 hours before tournament: 6am - 1am (next day) business_start_hour = 6 business_end_hour = 25 # 1am next day (25 in 24-hour format) + minutes_to_confirm = config.MINIMUM_RESPONSE_TIME + + live_testing = getattr(settings, 'LIVE_TESTING', False) + # Divide by 10 if LIVE_TESTING is enabled + if live_testing: + minutes_to_confirm = minutes_to_confirm / 10 # 8. Calculate raw deadline raw_deadline = current_time + timezone.timedelta(minutes=minutes_to_confirm) @@ -1637,7 +1638,7 @@ class Tournament(BaseModel): # Set to business start hour raw_deadline = raw_deadline.replace( - hour=BUSINESS_RULES["hours"]["default_confirmation_hour"], + hour=business_start_hour, minute=0, second=0, microsecond=0