|
|
|
@ -137,6 +137,63 @@ class TeamRegistration(SideStoreModel): |
|
|
|
def set_weight(self): |
|
|
|
def set_weight(self): |
|
|
|
self.weight = self.players_sorted_by_rank.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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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): |
|
|
|
def is_valid_for_summon(self): |
|
|
|
return self.players_sorted_by_rank.count() > 0 or self.name is not None |
|
|
|
return self.players_sorted_by_rank.count() > 0 or self.name is not None |
|
|
|
|