fix mail doubling

timetoconfirm
Raz 7 months ago
parent 7ea7f4ef6c
commit 1b39a3f340
  1. 57
      tournaments/models/team_registration.py
  2. 1
      tournaments/services/tournament_registration.py
  3. 2
      tournaments/signals.py

@ -137,6 +137,63 @@ class TeamRegistration(SideStoreModel):
def set_weight(self):
self.weight = self.players_sorted_by_rank.aggregate(total_weight=models.Sum('computed_rank'))['total_weight'] or 0
def has_changed(self, previous_instance):
"""
Compare the current instance with a previous instance to detect changes.
Args:
previous_instance (TeamRegistration): The previous version of the model instance
Returns:
bool: True if any significant fields have changed, False otherwise
"""
# Define the fields to compare
fields_to_compare = [
'weight',
'registration_date',
'bracket_position',
'group_stage_position',
'walk_out',
'wild_card_bracket',
'wild_card_group_stage',
'locked_weight',
]
# Check if previous_instance exists
if previous_instance is None:
return True
# Compare each field
for field in fields_to_compare:
current_value = getattr(self, field)
previous_value = getattr(previous_instance, field)
# Special handling for datetime fields to compare precisely
if field in ['registration_date']:
if (current_value is None and previous_value is not None) or \
(current_value is not None and previous_value is None):
return True
if current_value and previous_value:
# Compare with microsecond precision
if current_value.replace(microsecond=0) != previous_value.replace(microsecond=0):
return True
# For other fields, use standard comparison
elif current_value != previous_value:
return True
current_players = list(self.players_sorted_by_rank)
previous_players = list(previous_instance.players_sorted_by_rank)
if len(current_players) != len(previous_players):
return True
# Compare player details if needed
for current_player, previous_player in zip(current_players, previous_players):
if current_player.id != previous_player.id:
return True
return False
def is_valid_for_summon(self):
return self.players_sorted_by_rank.count() > 0 or self.name is not None

@ -383,6 +383,7 @@ class RegistrationCartManager:
# Calculate and set team weight
team_registration.set_weight()
team_registration.save()
# Update user phone if provided
if self.request.user.is_authenticated and mobile_number:

@ -166,7 +166,7 @@ def warn_team_walkout_status_change(sender, instance, **kwargs):
is_out = True
print(was_out, previous_instance.out_of_tournament(), is_out, instance.out_of_tournament())
if not instance.out_of_tournament() and is_out and (previous_instance.out_of_tournament() or not was_out):
if instance.has_changed(previous_instance) and not instance.out_of_tournament() and is_out and (previous_instance.out_of_tournament() or not was_out):
notify_team(instance, instance.tournament, TeamEmailType.OUT_OF_WALKOUT_WAITING_LIST)
elif was_out and not is_out:
waiting_list_teams = instance.tournament.waiting_list_teams(current_teams)

Loading…
Cancel
Save