|
|
|
@ -1,6 +1,6 @@ |
|
|
|
import random |
|
|
|
import random |
|
|
|
import string |
|
|
|
import string |
|
|
|
from django.db.models.signals import post_save, pre_delete |
|
|
|
from django.db.models.signals import post_save, pre_delete, post_delete |
|
|
|
from django.dispatch import receiver |
|
|
|
from django.dispatch import receiver |
|
|
|
from django.conf import settings |
|
|
|
from django.conf import settings |
|
|
|
from tournaments.models.tournament import Tournament |
|
|
|
from tournaments.models.tournament import Tournament |
|
|
|
@ -12,6 +12,8 @@ import requests |
|
|
|
from tournaments.services.email_service import TournamentEmailService |
|
|
|
from tournaments.services.email_service import TournamentEmailService |
|
|
|
from tournaments.models import PlayerDataSource |
|
|
|
from tournaments.models import PlayerDataSource |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tournament_deletion_in_progress = set() |
|
|
|
|
|
|
|
|
|
|
|
def generate_unique_code(): |
|
|
|
def generate_unique_code(): |
|
|
|
characters = string.ascii_lowercase + string.digits |
|
|
|
characters = string.ascii_lowercase + string.digits |
|
|
|
while True: |
|
|
|
while True: |
|
|
|
@ -59,13 +61,13 @@ def send_discord_message(webhook_url, content): |
|
|
|
f'Error sending message to Discord webhook: {response.status_code}, {response.text}' |
|
|
|
f'Error sending message to Discord webhook: {response.status_code}, {response.text}' |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_delete, sender=TeamRegistration) |
|
|
|
@receiver(post_delete, sender=TeamRegistration) |
|
|
|
def unregister_team(sender, instance, **kwargs): |
|
|
|
def unregister_team(sender, instance, **kwargs): |
|
|
|
team_registration = instance |
|
|
|
team_registration = instance |
|
|
|
tournament = instance.tournament |
|
|
|
tournament = instance.tournament |
|
|
|
|
|
|
|
global tournament_deletion_in_progress |
|
|
|
# Skip creating unregistration records if tournament is being deleted |
|
|
|
print('pre_delete TeamRegistration', tournament_deletion_in_progress) |
|
|
|
if not tournament or tournament._being_deleted == True: |
|
|
|
if tournament.id in tournament_deletion_in_progress: |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
first_waiting_list_team = tournament.first_waiting_list_team() |
|
|
|
first_waiting_list_team = tournament.first_waiting_list_team() |
|
|
|
@ -117,10 +119,18 @@ def unregister_team(sender, instance, **kwargs): |
|
|
|
other_player |
|
|
|
other_player |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=Tournament) |
|
|
|
|
|
|
|
def tournament_deletion(sender, instance, **kwargs): |
|
|
|
|
|
|
|
global tournament_deletion_in_progress |
|
|
|
|
|
|
|
tournament_deletion_in_progress.discard(instance.id) |
|
|
|
|
|
|
|
print('post tournament_deletion_in_progress', tournament_deletion_in_progress) |
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_delete, sender=Tournament) |
|
|
|
@receiver(pre_delete, sender=Tournament) |
|
|
|
def notify_players_of_tournament_cancellation(sender, instance, **kwargs): |
|
|
|
def notify_players_of_tournament_cancellation(sender, instance, **kwargs): |
|
|
|
tournament = instance |
|
|
|
tournament = instance |
|
|
|
|
|
|
|
global tournament_deletion_in_progress |
|
|
|
|
|
|
|
tournament_deletion_in_progress.add(instance.id) |
|
|
|
|
|
|
|
print('pre tournament_deletion_in_progress', tournament_deletion_in_progress) |
|
|
|
# Get all team registrations |
|
|
|
# Get all team registrations |
|
|
|
team_registrations = tournament.teamregistration_set.all() |
|
|
|
team_registrations = tournament.teamregistration_set.all() |
|
|
|
|
|
|
|
|
|
|
|
|