|
|
|
@ -50,10 +50,39 @@ def notify_object_creation_on_discord(created, instance): |
|
|
|
send_discord_log_message(message) |
|
|
|
send_discord_log_message(message) |
|
|
|
|
|
|
|
|
|
|
|
def notify_team(team, tournament, message_type): |
|
|
|
def notify_team(team, tournament, message_type): |
|
|
|
|
|
|
|
#print(team, message_type) |
|
|
|
if tournament.enable_online_registration is False: |
|
|
|
if tournament.enable_online_registration is False: |
|
|
|
return |
|
|
|
return |
|
|
|
print(team, message_type) |
|
|
|
if team.has_registered_online() is False: |
|
|
|
TournamentEmailService.notify_team(team, tournament, message_type) |
|
|
|
return |
|
|
|
|
|
|
|
if tournament.should_be_over(): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
if tournament.supposedly_in_progress(): |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
captain = None |
|
|
|
|
|
|
|
other_player = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for player in team.playerregistration_set.all(): |
|
|
|
|
|
|
|
if player.captain: |
|
|
|
|
|
|
|
captain = player |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
other_player = player |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if captain: |
|
|
|
|
|
|
|
TournamentEmailService.notify(captain, other_player, tournament, message_type) |
|
|
|
|
|
|
|
if not captain.registered_online or not captain.email: |
|
|
|
|
|
|
|
TournamentEmailService.notify(other_player, captain, tournament, message_type) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
# Notify both players separately if there is no captain or the captain is unavailable |
|
|
|
|
|
|
|
players = list(team.playerregistration_set.all()) |
|
|
|
|
|
|
|
if len(players) == 2: |
|
|
|
|
|
|
|
first_player, second_player = players |
|
|
|
|
|
|
|
TournamentEmailService.notify(first_player, second_player, tournament, message_type) |
|
|
|
|
|
|
|
TournamentEmailService.notify(second_player, first_player, tournament, message_type) |
|
|
|
|
|
|
|
elif len(players) == 1: |
|
|
|
|
|
|
|
# If there's only one player, just send them the notification |
|
|
|
|
|
|
|
TournamentEmailService.notify(players[0], None, tournament, message_type) |
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_delete, sender=TeamRegistration) |
|
|
|
@receiver(pre_delete, sender=TeamRegistration) |
|
|
|
def unregister_team(sender, instance, **kwargs): |
|
|
|
def unregister_team(sender, instance, **kwargs): |
|
|
|
@ -63,7 +92,8 @@ def unregister_team(sender, instance, **kwargs): |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.UNREGISTERED) |
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.UNREGISTERED) |
|
|
|
first_waiting_list_team = instance.tournament.first_waiting_list_team() |
|
|
|
teams = instance.tournament.teams(True) |
|
|
|
|
|
|
|
first_waiting_list_team = instance.tournament.first_waiting_list_team(teams) |
|
|
|
if first_waiting_list_team and first_waiting_list_team.id != instance.id: |
|
|
|
if first_waiting_list_team and first_waiting_list_team.id != instance.id: |
|
|
|
notify_team(first_waiting_list_team, instance.tournament, TeamEmailType.OUT_OF_WAITING_LIST) |
|
|
|
notify_team(first_waiting_list_team, instance.tournament, TeamEmailType.OUT_OF_WAITING_LIST) |
|
|
|
|
|
|
|
|
|
|
|
@ -122,48 +152,40 @@ def check_waiting_list(sender, instance, **kwargs): |
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_save, sender=TeamRegistration) |
|
|
|
@receiver(pre_save, sender=TeamRegistration) |
|
|
|
def warn_team_walkout_status_change(sender, instance, **kwargs): |
|
|
|
def warn_team_walkout_status_change(sender, instance, **kwargs): |
|
|
|
if instance.id is None: |
|
|
|
if instance.id is None or instance.tournament.enable_online_registration is False: |
|
|
|
return |
|
|
|
|
|
|
|
if instance.tournament.enable_online_registration is False: |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
previous_instance = None |
|
|
|
try: |
|
|
|
try: |
|
|
|
previous_instance = TeamRegistration.objects.get(id=instance.id) |
|
|
|
previous_instance = TeamRegistration.objects.get(id=instance.id) |
|
|
|
except TeamRegistration.DoesNotExist: |
|
|
|
except TeamRegistration.DoesNotExist: |
|
|
|
previous_instance = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if previous_instance is None: |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
previous_teams = previous_instance.tournament.teams(True) |
|
|
|
previous_teams = instance.tournament.teams(True) |
|
|
|
current_teams = instance.tournament.teams(True, instance) |
|
|
|
current_teams = instance.tournament.teams(True, instance) |
|
|
|
previous_retrieved_teams = [team for team in previous_teams if team.team_registration.id == previous_instance.id] |
|
|
|
previous_retrieved_teams = [team for team in previous_teams if team.team_registration.id == previous_instance.id] |
|
|
|
current_retrieved_teams = [team for team in current_teams if team.team_registration.id == instance.id] |
|
|
|
current_retrieved_teams = [team for team in current_teams if team.team_registration.id == instance.id] |
|
|
|
was_out = previous_instance.out_of_tournament() |
|
|
|
was_out = previous_instance.out_of_tournament() |
|
|
|
is_out = instance.out_of_tournament() |
|
|
|
is_out = instance.out_of_tournament() |
|
|
|
if len(previous_retrieved_teams) > 0: |
|
|
|
if len(previous_retrieved_teams) > 0 and previous_retrieved_teams[0].stage == "Attente": |
|
|
|
if previous_retrieved_teams[0].stage == "Attente": |
|
|
|
was_out = True |
|
|
|
was_out = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(current_retrieved_teams) > 0: |
|
|
|
if len(current_retrieved_teams) > 0 and current_retrieved_teams[0].stage == "Attente": |
|
|
|
if current_retrieved_teams[0].stage == "Attente": |
|
|
|
is_out = True |
|
|
|
is_out = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(was_out, previous_instance.out_of_tournament(), is_out, instance.out_of_tournament()) |
|
|
|
print(was_out, previous_instance.out_of_tournament(), is_out, instance.out_of_tournament()) |
|
|
|
if not instance.out_of_tournament() and is_out: |
|
|
|
if 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) |
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.OUT_OF_WALKOUT_WAITING_LIST) |
|
|
|
|
|
|
|
elif was_out and not is_out: |
|
|
|
if not previous_instance.out_of_tournament() and instance.out_of_tournament(): |
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.OUT_OF_WALKOUT_IS_IN) |
|
|
|
|
|
|
|
elif not previous_instance.out_of_tournament() and instance.out_of_tournament(): |
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.WALKOUT) |
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.WALKOUT) |
|
|
|
|
|
|
|
|
|
|
|
if was_out and not is_out: |
|
|
|
if was_out and not is_out: |
|
|
|
is_in, first_out_of_list = instance.tournament.first_out_of_list(instance) |
|
|
|
first_out_of_list = instance.tournament.first_waiting_list_team(current_teams) |
|
|
|
if is_in: |
|
|
|
|
|
|
|
notify_team(instance, instance.tournament, TeamEmailType.OUT_OF_WALKOUT_IS_IN) |
|
|
|
|
|
|
|
if first_out_of_list: |
|
|
|
if first_out_of_list: |
|
|
|
notify_team(first_out_of_list, instance.tournament, TeamEmailType.UNEXPECTED_OUT_OF_TOURNAMENT) |
|
|
|
notify_team(first_out_of_list, instance.tournament, TeamEmailType.UNEXPECTED_OUT_OF_TOURNAMENT) |
|
|
|
|
|
|
|
|
|
|
|
elif not was_out and is_out: |
|
|
|
elif not was_out and is_out: |
|
|
|
first_waiting_list_team = instance.tournament.first_waiting_list_team() |
|
|
|
first_waiting_list_team = instance.tournament.first_waiting_list_team(previous_teams) |
|
|
|
if first_waiting_list_team: |
|
|
|
if first_waiting_list_team: |
|
|
|
notify_team(first_waiting_list_team, instance.tournament, TeamEmailType.OUT_OF_WAITING_LIST) |
|
|
|
notify_team(first_waiting_list_team, instance.tournament, TeamEmailType.OUT_OF_WAITING_LIST) |
|
|
|
|