From 3c500643b1a59d6c10cae186de7add4b1093dad5 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 13 May 2024 11:05:40 +0200 Subject: [PATCH] Fixes missing saved fields --- tournaments/admin.py | 2 +- .../migrations/0040_groupstage_name.py | 18 +++++++++ .../0041_teamregistration_weight.py | 18 +++++++++ ...teamregistration_locked_weight_and_more.py | 38 +++++++++++++++++++ tournaments/models/court.py | 4 +- tournaments/models/group_stage.py | 13 ++++--- tournaments/models/match.py | 2 +- tournaments/models/player_registration.py | 2 +- tournaments/models/team_registration.py | 6 +-- tournaments/models/tournament.py | 2 +- tournaments/serializers.py | 1 - tournaments/views.py | 1 + 12 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 tournaments/migrations/0040_groupstage_name.py create mode 100644 tournaments/migrations/0041_teamregistration_weight.py create mode 100644 tournaments/migrations/0042_rename_lock_weight_teamregistration_locked_weight_and_more.py diff --git a/tournaments/admin.py b/tournaments/admin.py index c884873..759f9e6 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -42,7 +42,7 @@ class MatchAdmin(admin.ModelAdmin): list_display = ['__str__', 'round', 'group_stage', 'start_date', 'index'] class GroupStageAdmin(admin.ModelAdmin): - list_display = ['tournament', 'index'] + list_display = ['tournament', 'index', 'start_date'] class EventAdmin(admin.ModelAdmin): list_display = ['name', 'club', 'creation_date', 'creator'] diff --git a/tournaments/migrations/0040_groupstage_name.py b/tournaments/migrations/0040_groupstage_name.py new file mode 100644 index 0000000..ecf93dd --- /dev/null +++ b/tournaments/migrations/0040_groupstage_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-05-12 14:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0039_rename_call_display_entry_fee_customuser_summons_display_entry_fee_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='groupstage', + name='name', + field=models.CharField(blank=True, max_length=200, null=True), + ), + ] diff --git a/tournaments/migrations/0041_teamregistration_weight.py b/tournaments/migrations/0041_teamregistration_weight.py new file mode 100644 index 0000000..545f26e --- /dev/null +++ b/tournaments/migrations/0041_teamregistration_weight.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2024-05-12 14:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0040_groupstage_name'), + ] + + operations = [ + migrations.AddField( + model_name='teamregistration', + name='weight', + field=models.IntegerField(default=0), + ), + ] diff --git a/tournaments/migrations/0042_rename_lock_weight_teamregistration_locked_weight_and_more.py b/tournaments/migrations/0042_rename_lock_weight_teamregistration_locked_weight_and_more.py new file mode 100644 index 0000000..cdd91ed --- /dev/null +++ b/tournaments/migrations/0042_rename_lock_weight_teamregistration_locked_weight_and_more.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.11 on 2024-05-13 09:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('tournaments', '0041_teamregistration_weight'), + ] + + operations = [ + migrations.RenameField( + model_name='teamregistration', + old_name='lock_weight', + new_name='locked_weight', + ), + migrations.AddField( + model_name='court', + name='exit_allowed', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='court', + name='indoor', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='teamregistration', + name='confirmation_date', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='playerregistration', + name='birthdate', + field=models.CharField(blank=True, max_length=20, null=True), + ), + ] diff --git a/tournaments/models/court.py b/tournaments/models/court.py index 7742d16..1e9e24c 100644 --- a/tournaments/models/court.py +++ b/tournaments/models/court.py @@ -7,5 +7,5 @@ class Court(models.Model): index = models.IntegerField(default=0) club = models.ForeignKey(Club, on_delete=models.CASCADE) name = models.CharField(max_length=50, null=True, blank=True) - #exit_allowed = models.BooleanField(default=False) - #indoor = models.BooleanField(default=False) + exit_allowed = models.BooleanField(default=False) + indoor = models.BooleanField(default=False) diff --git a/tournaments/models/group_stage.py b/tournaments/models/group_stage.py index 61b2726..83dffd2 100644 --- a/tournaments/models/group_stage.py +++ b/tournaments/models/group_stage.py @@ -15,10 +15,13 @@ class GroupStage(models.Model): name = models.CharField(max_length=200, null=True, blank=True) def __str__(self): - return f"{self.tournament.display_name()} - {self.name()}" + return f"{self.tournament.display_name()} - {self.display_name()}" - def name(self): - return f"Poule {self.index}" + def display_name(self): + if self.name: + return self.name + else: + return f"Poule {self.index}" def next_match(self, player_registration): matches = self.matches_for_registration(player_registration).filter(end_date__isnull=False).order_by('start_date') @@ -29,7 +32,7 @@ class GroupStage(models.Model): return [ts.match for ts in team_scores] # map(lambda ts: ts.match, team_scores) def live_group_stages(self): - lgs = LiveGroupStage(self.name()) + lgs = LiveGroupStage(self.display_name()) gs_teams = {} # init all teams @@ -134,7 +137,7 @@ class GroupStageTeam: self.wins = 0 self.losses = 0 self.diff = 0 - self.weight = team_registration.weight() + self.weight = team_registration.get_weight() def wins_losses(self): return f"{self.wins}/{self.losses}" diff --git a/tournaments/models/match.py b/tournaments/models/match.py index bde5bcb..b4c42a0 100644 --- a/tournaments/models/match.py +++ b/tournaments/models/match.py @@ -127,7 +127,7 @@ class Match(models.Model): image = team_score.team_registration.logo names = team_score.team_names() scores = team_score.scores_array() - weight = team_score.team_registration.weight() + weight = team_score.team_registration.get_weight() is_winner = team_score.team_registration.id == self.winning_team_id walk_out = team_score.walk_out team = Team(image, names, scores, weight, is_winner, walk_out) diff --git a/tournaments/models/player_registration.py b/tournaments/models/player_registration.py index b88b997..3087151 100644 --- a/tournaments/models/player_registration.py +++ b/tournaments/models/player_registration.py @@ -27,7 +27,7 @@ class PlayerRegistration(models.Model): phone_number = models.CharField(max_length=15, null=True, blank=True) email = models.CharField(max_length=50, null=True, blank=True) - birthdate = models.DateTimeField(null=True, blank=True) + birthdate = models.CharField(max_length=20, null=True, blank=True) computed_rank = models.IntegerField(default=0) diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 5cebff7..e5dd166 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -22,9 +22,9 @@ class TeamRegistration(models.Model): wild_card_bracket = models.BooleanField(default=False) wild_card_group_stage = models.BooleanField(default=False) weight = models.IntegerField(default=0) - lock_weight = models.IntegerField(null=True, blank=True) + locked_weight = models.IntegerField(null=True, blank=True) - #confirmation_date = models.DateTimeField(null=True, blank=True) + confirmation_date = models.DateTimeField(null=True, blank=True) qualified = models.BooleanField(default=False) def __str__(self): @@ -71,7 +71,7 @@ class TeamRegistration(models.Model): else: return "--" - def weight(self): + def get_weight(self): top_two_players = self.playerregistration_set.all().order_by('rank')[:2] weight = 0 for player in top_two_players: diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 0bcda96..cbb49b2 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -70,7 +70,7 @@ class Tournament(models.Model): if next_match: names = team_registration.team_names() stage = next_match.stage_name() - weight = team_registration.weight() + weight = team_registration.get_weight() summon = TeamSummon(names, next_match.start_date, weight, stage, team_registration.logo) summons.append(summon) diff --git a/tournaments/serializers.py b/tournaments/serializers.py index f11aba4..d3d6db6 100644 --- a/tournaments/serializers.py +++ b/tournaments/serializers.py @@ -116,7 +116,6 @@ class RoundSerializer(serializers.ModelSerializer): class GroupStageSerializer(serializers.ModelSerializer): class Meta: - # tournament_id = serializers.PrimaryKeyRelatedField(queryset=Tournament.objects.all()) model = GroupStage fields = '__all__' # ['id', 'index', 'tournament_id', 'format'] diff --git a/tournaments/views.py b/tournaments/views.py index 6e5f683..e8836d2 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -219,6 +219,7 @@ def user_by_token(request): class UserViewSet(viewsets.ModelViewSet): queryset = CustomUser.objects.all() serializer_class = UserUpdateSerializer + permission_classes = [] # Users are public whereas the other requests are only for logged users def get_serializer_class(self): # Use UserSerializer for other actions (e.g., create, retrieve)