remove players property method and replace it with players_sorted_by_rank, fix and made consistent running footer

timetoconfirm
Raz 7 months ago
parent 147a736c35
commit 840d11ea7e
  1. 2
      api/views.py
  2. 2
      tournaments/models/group_stage.py
  3. 26
      tournaments/models/team_registration.py
  4. 2
      tournaments/models/team_score.py
  5. 2
      tournaments/models/tournament.py
  6. 5
      tournaments/services/email_service.py
  7. 2
      tournaments/services/tournament_unregistration.py
  8. 19
      tournaments/templates/tournaments/match_cell.html
  9. 2
      tournaments/templates/tournaments/team_details.html
  10. 2
      tournaments/templates/tournaments/tournament_info.html

@ -317,7 +317,7 @@ def process_refund(request, team_registration_id):
return Response({
'success': success,
'message': message,
'players': team_registration.players.all()
'players': team_registration.players_sorted_by_rank
})
except Exception as e:
return Response({

@ -220,7 +220,7 @@ class GroupStageTeam:
self.set_diff = 0
self.game_diff = 0
self.display_set_difference = False
if team_registration.player_registrations.count() == 0:
if team_registration.players_sorted_by_rank.count() == 0:
weight = None
else:
weight = team_registration.weight

@ -56,7 +56,7 @@ class TeamRegistration(SideStoreModel):
return None
def player_names_as_list(self):
players = list(self.player_registrations.all())
players = list(self.players_sorted_by_rank)
if len(players) == 0:
return []
elif len(players) == 1:
@ -74,7 +74,7 @@ class TeamRegistration(SideStoreModel):
if self.name:
return [self.name] #add an empty line if it's a team name
else:
players = list(self.player_registrations.all())
players = list(self.players_sorted_by_rank)
if len(players) == 0:
if self.wild_card_bracket:
return ['Place réservée wildcard']
@ -88,7 +88,7 @@ class TeamRegistration(SideStoreModel):
return [pr.shortened_name() for pr in players]
@property
def players(self):
def players_sorted_by_rank(self):
# Fetch related PlayerRegistration objects
return self.player_registrations.all().order_by('rank')
@ -103,7 +103,7 @@ class TeamRegistration(SideStoreModel):
def formatted_team_names(self):
if self.name:
return self.name
names = [pr.last_name for pr in self.player_registrations.all()][:2] # Take max first 2
names = [pr.last_name for pr in self.players_sorted_by_rank][:2] # Take max first 2
joined_names = " / ".join(names)
if joined_names:
return f"Paire {joined_names}"
@ -135,11 +135,11 @@ class TeamRegistration(SideStoreModel):
return "--"
def set_weight(self):
self.weight = self.player_registrations.aggregate(total_weight=models.Sum('computed_rank'))['total_weight'] or 0
self.weight = self.players_sorted_by_rank.aggregate(total_weight=models.Sum('computed_rank'))['total_weight'] or 0
self.save() # Save the updated weight if necessary
def is_valid_for_summon(self):
return self.player_registrations.count() > 0 or self.name is not None
return self.players_sorted_by_rank.count() > 0 or self.name is not None
def initial_weight(self):
if self.locked_weight is None:
@ -167,7 +167,7 @@ class TeamRegistration(SideStoreModel):
return self.walk_out
def get_other_player(self, player):
for p in self.player_registrations.all():
for p in self.players_sorted_by_rank:
if p != player:
return p
return None
@ -298,7 +298,7 @@ class TeamRegistration(SideStoreModel):
return None
def has_registered_online(self):
for p in self.player_registrations.all():
for p in self.players_sorted_by_rank:
if p.registered_online:
return True
return False
@ -311,7 +311,7 @@ class TeamRegistration(SideStoreModel):
return ""
def set_time_to_confirm(self, ttc):
for p in self.player_registrations.all():
for p in self.players_sorted_by_rank:
if p.registered_online:
p.time_to_confirm = ttc
if ttc is None:
@ -324,18 +324,18 @@ class TeamRegistration(SideStoreModel):
"""Check if this team needs to confirm their registration"""
# Check if any player has status PENDING and is registered online
return any(p.registration_status == RegistrationStatus.PENDING and p.registered_online
for p in self.player_registrations.all())
for p in self.players_sorted_by_rank)
def get_confirmation_deadline(self):
"""Get the confirmation deadline for this team"""
deadlines = [p.time_to_confirm for p in self.player_registrations.all() if p.time_to_confirm is not None]
deadlines = [p.time_to_confirm for p in self.players_sorted_by_rank if p.time_to_confirm is not None]
return max(deadlines) if deadlines else None
def confirm_registration(self, payment_intent_id=None):
"""Confirm the team's registration after being moved from waiting list"""
now = timezone.now()
# Update all players in the team
for player in self.player_registrations.all():
for player in self.players_sorted_by_rank:
player.time_to_confirm = None
player.payment_id = payment_intent_id
if payment_intent_id is not None:
@ -357,7 +357,7 @@ class TeamRegistration(SideStoreModel):
- 'MIXED': If some players have paid and others haven't (unusual case)
"""
# Get all player registrations for this team
player_registrations = self.player_registrations.all()
player_registrations = self.players_sorted_by_rank
# If we have no players, return None
if not player_registrations.exists():

@ -114,7 +114,7 @@ class TeamScore(SideStoreModel):
id = self.team_registration.id
image = self.team_registration.logo
is_winner = self.team_registration.id == match.winning_team_id
if self.team_registration.player_registrations.count() == 0:
if self.team_registration.players_sorted_by_rank.count() == 0:
weight = None
else:
weight = self.team_registration.weight

@ -1824,7 +1824,7 @@ class TeamItem:
self.names = team_registration.team_names()
self.date = team_registration.local_call_date()
self.registration_date = team_registration.registration_date
if team_registration.player_registrations.count() == 0:
if team_registration.players_sorted_by_rank.count() == 0:
weight = None
else:
weight = team_registration.weight

@ -2,7 +2,6 @@ from django.core.mail import EmailMessage
from enum import Enum
from ..models.enums import RegistrationStatus
from ..models.tournament import TeamSortingType
import django.utils.timezone
class TeamEmailType(Enum):
REGISTERED = "registered"
@ -484,7 +483,7 @@ class TournamentEmailService:
@staticmethod
def notify_team(team, tournament, message_type: TeamEmailType):
# Notify both players separately if there is no captain or the captain is unavailable
players = list(team.player_registrations.all())
players = list(team.players_sorted_by_rank)
if len(players) == 2:
print("TournamentEmailService.notify_team 2p", team)
first_player, second_player = players
@ -533,7 +532,7 @@ class TournamentEmailService:
team_registration: The team registration
refund_details: The refund details from Stripe
"""
player_registrations = team_registration.player_registrations.all()
player_registrations = team_registration.players_sorted_by_rank
refund_amount = None
if refund_details and 'amount' in refund_details:
# Convert cents to euros

@ -83,7 +83,7 @@ class TournamentUnregistrationService:
unregistration_date=timezone.now(),
)
for player in team_registration.player_registrations.all():
for player in team_registration.players_sorted_by_rank:
UnregisteredPlayer.objects.create(
unregistered_team=unregistered_team,
first_name=player.first_name,

@ -15,24 +15,29 @@
{% for team in match.teams %}
<div class="match-result {% cycle 'bottom-border' '' %}">
<div class="player {% if team.names|length == 1 %}single-player{% else %}two-players{% endif %}">
<div class="flex-row">
{% if team.id and team.weight %}
<a href="{% url 'team-details' tournament.id team.id %}" class="player-link">
{% endif %}
{% if team.is_lucky_loser or team.walk_out == 1 %}
<div class="overlay-text">
{% if match.should_show_lucky_loser_status and team.is_lucky_loser %}(LL){% elif team.walk_out == 1 %}(WO){% endif %}
</div>
{% endif %}
<div>
{% for name in team.names %}
<div class="semibold{% if team.walk_out == 1 %} strikethrough{% endif %}{% if team.is_winner %} winner{% endif %}">
{{ name }}
</div>
{% endfor %}
</div>
{% if team.id and team.weight %}
</a>
{% endif %}
{% if team.is_lucky_loser or team.walk_out == 1 %}
<div class="minor-info bold" style="height: 100%; padding-right: 20px;">
{% if match.should_show_lucky_loser_status and team.is_lucky_loser %}(LL){% elif team.walk_out == 1 %}(WO){% endif %}
</div>
{% endif %}
</div>
</div>
{% if match.has_walk_out %}

@ -15,7 +15,7 @@
<div class="cell medium-12">
<h1 class="club padding10 topmargin20">{{ team.formatted_team_names }} {{team.formatted_special_status}}</h1>
<div class="grid-x">
{% for player in team.player_registrations.all %}
{% for player in team.players_sorted_by_rank.all %}
{% include 'tournaments/player_row.html' with player=player %}
{% endfor %}
{% include 'tournaments/team_stats.html' %}

@ -73,7 +73,7 @@
</div>
<div class="semibold topmargin20">
{% for player in team.players %}
{% for player in team.players_sorted_by_rank %}
<div>{{ player.name }}</div>
{% endfor %}
</div>

Loading…
Cancel
Save