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({ return Response({
'success': success, 'success': success,
'message': message, 'message': message,
'players': team_registration.players.all() 'players': team_registration.players_sorted_by_rank
}) })
except Exception as e: except Exception as e:
return Response({ return Response({

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

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

@ -114,7 +114,7 @@ class TeamScore(SideStoreModel):
id = self.team_registration.id id = self.team_registration.id
image = self.team_registration.logo image = self.team_registration.logo
is_winner = self.team_registration.id == match.winning_team_id 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 weight = None
else: else:
weight = self.team_registration.weight weight = self.team_registration.weight

@ -1824,7 +1824,7 @@ class TeamItem:
self.names = team_registration.team_names() self.names = team_registration.team_names()
self.date = team_registration.local_call_date() self.date = team_registration.local_call_date()
self.registration_date = team_registration.registration_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 weight = None
else: else:
weight = team_registration.weight weight = team_registration.weight

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

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

@ -15,24 +15,29 @@
{% for team in match.teams %} {% for team in match.teams %}
<div class="match-result {% cycle 'bottom-border' '' %}"> <div class="match-result {% cycle 'bottom-border' '' %}">
<div class="player {% if team.names|length == 1 %}single-player{% else %}two-players{% endif %}"> <div class="player {% if team.names|length == 1 %}single-player{% else %}two-players{% endif %}">
<div class="flex-row">
{% if team.id and team.weight %} {% if team.id and team.weight %}
<a href="{% url 'team-details' tournament.id team.id %}" class="player-link"> <a href="{% url 'team-details' tournament.id team.id %}" class="player-link">
{% endif %} {% endif %}
<div>
{% 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 %}
{% for name in team.names %} {% for name in team.names %}
<div class="semibold{% if team.walk_out == 1 %} strikethrough{% endif %}{% if team.is_winner %} winner{% endif %}"> <div class="semibold{% if team.walk_out == 1 %} strikethrough{% endif %}{% if team.is_winner %} winner{% endif %}">
{{ name }} {{ name }}
</div> </div>
{% endfor %} {% endfor %}
</div>
{% if team.id and team.weight %} {% if team.id and team.weight %}
</a> </a>
{% endif %} {% 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> </div>
{% if match.has_walk_out %} {% if match.has_walk_out %}

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

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

Loading…
Cancel
Save