From a0998299eef376c6d48fae2b853872944462fd3d Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 12 Mar 2025 11:24:35 +0100 Subject: [PATCH] various fixes and improvements --- sync/views.py | 6 +++++- tournaments/models/match.py | 8 ++++---- tournaments/models/team_registration.py | 2 +- tournaments/services/email_service.py | 4 ++-- tournaments/templates/tournaments/group_stages.html | 1 - tournaments/views.py | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/sync/views.py b/sync/views.py index b83eff7..0f8f076 100644 --- a/sync/views.py +++ b/sync/views.py @@ -159,7 +159,11 @@ class SynchronizationApi(HierarchyApiView): except Exception as e: response_status = status.HTTP_400_BAD_REQUEST - print(f'OTHER exception on {model_operation} {model_name} : {str(e)}, type: {type(e)}, id: {data.get('id')}') + import traceback + tb = traceback.extract_tb(e.__traceback__) + file_name = tb[-1].filename + line_number = tb[-1].lineno + print(f'OTHER exception on {model_operation} {model_name} : {str(e)}, type: {type(e)}, id: {data.get('id')}, file: {file_name}, line: {line_number}') message = str(e) results.append({ diff --git a/tournaments/models/match.py b/tournaments/models/match.py index da10f00..ac9ee29 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -111,9 +111,9 @@ class Match(SideStoreModel): previous_round = None # Check if the next index is within the bounds of the rounds array - previous_round = self.round.tournament.round_set.filter(index=previous_index, parent = self.round.parent).first() + previous_round = self.round.tournament.rounds.filter(index=previous_index, parent = self.round.parent).first() if previous_round is None and self.round.parent is not None: - previous_round = self.round.tournament.round_set.filter(id=self.round.parent.id).first() + previous_round = self.round.tournament.rounds.filter(id=self.round.parent.id).first() return previous_round return None @@ -133,7 +133,7 @@ class Match(SideStoreModel): previous_round = self.get_loser_previous_round() match = None if previous_round: - matches = previous_round.match_set.all() # Retrieve the QuerySet + matches = previous_round.matches.all() # Retrieve the QuerySet match_index = self.index * 2 + 1 if top == False: match_index += 1 @@ -254,7 +254,7 @@ class Match(SideStoreModel): team = self.default_live_team(names) teams.append(existing_team) teams.append(team) - elif (self.round.parent is None and self.round.tournament.round_set.filter(parent__isnull=True, group_stage_loser_bracket=False).count() - 1 == self.round.index): + elif (self.round.parent is None and self.round.tournament.rounds.filter(parent__isnull=True, group_stage_loser_bracket=False).count() - 1 == self.round.index): match_index_within_round = self.index - (int(2 ** self.round.index) - 1) names = ["Qualifié", ''] team = self.default_live_team(names) diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 771354e..e4ef14e 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -281,7 +281,7 @@ class TeamRegistration(SideStoreModel): return None def has_registered_online(self): - for p in self.playerregistration_set.all(): + for p in self.player_registrations.all(): if p.registered_online: return True return False diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py index 68c418b..f334fbd 100644 --- a/tournaments/services/email_service.py +++ b/tournaments/services/email_service.py @@ -418,7 +418,7 @@ class TournamentEmailService: captain = None other_player = None - for player in team.playerregistration_set.all(): + for player in team.player_registrations.all(): if player.captain: captain = player else: @@ -428,7 +428,7 @@ class TournamentEmailService: TournamentEmailService.notify(captain, other_player, tournament, message_type) else: # Notify both players separately if there is no captain or the captain is unavailable - players = list(team.playerregistration_set.all()) + players = list(team.player_registrations.all()) if len(players) == 2: first_player, second_player = players TournamentEmailService.notify(first_player, second_player, tournament, message_type) diff --git a/tournaments/templates/tournaments/group_stages.html b/tournaments/templates/tournaments/group_stages.html index dfc1496..9d2a17e 100644 --- a/tournaments/templates/tournaments/group_stages.html +++ b/tournaments/templates/tournaments/group_stages.html @@ -4,7 +4,6 @@ {% block first_title %}{{ tournament.event.display_name }}{% endblock %} {% block second_title %}{{ tournament.display_name }}{% endblock %} {% block title_link %}{% url 'tournament' tournament.id %}{% endblock %} -{% if tournament.display_group_stages %} {% block content %} {% if tournament.display_group_stages %} diff --git a/tournaments/views.py b/tournaments/views.py index e308f02..3fa35aa 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -938,7 +938,7 @@ def tournament_bracket(request, tournament_id): else: first_half_matches = list(matches) # Convert QuerySet to a list if loser_final: - loser_matches = loser_final.match_set.all() + loser_matches = loser_final.matches.all() if len(loser_matches) >= 1: first_half_matches.append(loser_matches[0])