diff --git a/db.sqlite3.main b/db.sqlite3.main new file mode 100644 index 0000000..9e8eb32 Binary files /dev/null and b/db.sqlite3.main differ diff --git a/sync/consumers.py b/sync/consumers.py index 77cbc82..d2c8825 100644 --- a/sync/consumers.py +++ b/sync/consumers.py @@ -8,8 +8,6 @@ class UserConsumer(WebsocketConsumer): self.user_id = self.scope["url_route"]["kwargs"]["user_id"] self.group_name = f"sync_{self.user_id}" - print(f'connect, group_name = {self.group_name}') - # Join room group async_to_sync(self.channel_layer.group_add)( self.group_name, self.channel_name diff --git a/tournaments/migrations/0096_drawlog_creation_date_drawlog_last_update_and_more.py b/tournaments/migrations/0096_drawlog_creation_date_drawlog_last_update_and_more.py new file mode 100644 index 0000000..4c13234 --- /dev/null +++ b/tournaments/migrations/0096_drawlog_creation_date_drawlog_last_update_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 5.1 on 2024-12-13 14:18 + +import django.db.models.deletion +import django.utils.timezone +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0095_club_creation_date_club_last_update_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='drawlog', + name='creation_date', + field=models.DateTimeField(default=django.utils.timezone.now, editable=False), + ), + migrations.AddField( + model_name='drawlog', + name='last_update', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + migrations.AddField( + model_name='drawlog', + name='last_updated_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='drawlog', + name='related_user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='drawlog', + name='store_id', + field=models.CharField(default='', max_length=100), + ), + ] diff --git a/tournaments/migrations/0096_special_store_id.py b/tournaments/migrations/0096_special_store_id.py deleted file mode 100644 index ffc103f..0000000 --- a/tournaments/migrations/0096_special_store_id.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 5.1 on 2024-12-13 13:04 - -from django.db import migrations - -def init_store_id(apps, schema_editor): - models = ["GroupStage", "Round", "TeamRegistration", "PlayerRegistration", "Match", "TeamScore", "DrawLog"] - for model in models: - Model = apps.get_model("tournaments", model) - for instance in Model.objects.all(): - instance.store_id = str(instance.tournament_id()) - instance.save() - -def init_related_names(apps, schema_editor): - models = ["Club", "Event"] - for model in models: - Model = apps.get_model("tournaments", model) - for instance in Model.objects.all(): - instance.related_user = instance.creator - instance.save() - -class Migration(migrations.Migration): - - dependencies = [ - ('tournaments', '0095_club_creation_date_club_last_update_and_more'), - ] - - operations = [ - migrations.RunPython(init_store_id), - migrations.RunPython(init_related_names), - ] diff --git a/tournaments/migrations/0097_special_store_id.py b/tournaments/migrations/0097_special_store_id.py new file mode 100644 index 0000000..c9314b9 --- /dev/null +++ b/tournaments/migrations/0097_special_store_id.py @@ -0,0 +1,69 @@ +# Generated by Django 5.1 on 2024-12-13 13:04 + +from django.db import migrations + +def init_store_id(apps, schema_editor): + GroupStage = apps.get_model("tournaments", "GroupStage") + for instance in GroupStage.objects.all(): + instance.store_id = str(instance.tournament.id) + instance.save() + + Round = apps.get_model("tournaments", "Round") + for instance in Round.objects.all(): + instance.store_id = str(instance.tournament.id) + instance.save() + + TeamRegistration = apps.get_model("tournaments", "TeamRegistration") + for instance in TeamRegistration.objects.all(): + instance.store_id = str(instance.tournament.id) + instance.save() + + PlayerRegistration = apps.get_model("tournaments", "PlayerRegistration") + for instance in PlayerRegistration.objects.all(): + instance.store_id = str(instance.team_registration.tournament.id) + instance.save() + + Match = apps.get_model("tournaments", "Match") + for instance in Match.objects.all(): + if instance.round: + id = instance.round.tournament.id + else: + id = instance.group_stage.tournament.id + instance.store_id = str(id) + instance.save() + + TeamScore = apps.get_model("tournaments", "TeamScore") + for instance in TeamScore.objects.all(): + if instance.team_registration: + id = instance.team_registration.tournament.id + else: + if instance.match.round: + id = instance.round.tournament.id + else: + id = instance.group_stage.tournament.id + instance.store_id = str(id) + instance.save() + + DrawLog = apps.get_model("tournaments", "DrawLog") + for instance in DrawLog.objects.all(): + instance.store_id = str(instance.tournament.id) + instance.save() + +def init_related_names(apps, schema_editor): + models = ["Club", "Event"] + for model in models: + Model = apps.get_model("tournaments", model) + for instance in Model.objects.all(): + instance.related_user = instance.creator + instance.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0096_drawlog_creation_date_drawlog_last_update_and_more'), + ] + + operations = [ + migrations.RunPython(init_store_id), + migrations.RunPython(init_related_names), + ] diff --git a/tournaments/models/draw_log.py b/tournaments/models/draw_log.py index 99df240..afda9cc 100644 --- a/tournaments/models/draw_log.py +++ b/tournaments/models/draw_log.py @@ -4,7 +4,7 @@ import uuid class DrawLog(SideStoreModel): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True) - tournament = models.ForeignKey('Tournament', on_delete=models.CASCADE) + tournament = models.ForeignKey('Tournament', on_delete=models.CASCADE, related_name='draw_logs') draw_date = models.DateTimeField() draw_seed = models.IntegerField() draw_match_index = models.IntegerField() @@ -15,8 +15,8 @@ class DrawLog(SideStoreModel): return f'{self.draw_date}' def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) - def tournament_id(self): + def get_tournament_id(self): return self.tournament.id diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index 6c95758..990b608 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -22,10 +22,10 @@ class GroupStage(SideStoreModel): return self.display_name() def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) - def tournament_id(self): + def get_tournament_id(self): return self.tournament.id def display_name(self): diff --git a/tournaments/models/match.py b/tournaments/models/match.py index baa3bbd..eceb32f 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -32,7 +32,7 @@ class Match(SideStoreModel): return f"{self.stage_name()} #{self.index}: {names}" def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) def tournament(self): @@ -41,7 +41,7 @@ class Match(SideStoreModel): else: return self.group_stage.tournament - def tournament_id(self): + def get_tournament_id(self): return self.tournament().id def court_name(self, index): diff --git a/tournaments/models/player_registration.py b/tournaments/models/player_registration.py index 057a931..9c81030 100644 --- a/tournaments/models/player_registration.py +++ b/tournaments/models/player_registration.py @@ -38,10 +38,10 @@ class PlayerRegistration(SideStoreModel): return self.name() def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) - def tournament_id(self): + def get_tournament_id(self): return self.team_registration.tournament.id def name(self): diff --git a/tournaments/models/round.py b/tournaments/models/round.py index 87a5b0f..c19b1a5 100644 --- a/tournaments/models/round.py +++ b/tournaments/models/round.py @@ -19,10 +19,10 @@ class Round(SideStoreModel): return self.name() def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) - def tournament_id(self): + def get_tournament_id(self): return self.tournament.id def name(self): diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index dcdffa7..b44ba24 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -37,10 +37,10 @@ class TeamRegistration(SideStoreModel): return self.player_names() def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) - def tournament_id(self): + def get_tournament_id(self): return self.tournament.id def team_names(self): diff --git a/tournaments/models/team_score.py b/tournaments/models/team_score.py index b2ea53f..f570bc3 100644 --- a/tournaments/models/team_score.py +++ b/tournaments/models/team_score.py @@ -14,7 +14,7 @@ class TeamScore(SideStoreModel): return f"{self.match.stage_name()} #{self.match.index}: {self.player_names()}" def save(self, *args, **kwargs): - self.store_id = str(self.tournament_id()) + self.store_id = str(self.get_tournament_id()) super().save(*args, **kwargs) def tournament(self): @@ -25,7 +25,7 @@ class TeamScore(SideStoreModel): else: return None - def tournament_id(self): + def get_tournament_id(self): return self.tournament().id def player_names(self):