Fixes missing saved fields

clubs
Laurent 2 years ago
parent edf5c870f1
commit 3c500643b1
  1. 2
      tournaments/admin.py
  2. 18
      tournaments/migrations/0040_groupstage_name.py
  3. 18
      tournaments/migrations/0041_teamregistration_weight.py
  4. 38
      tournaments/migrations/0042_rename_lock_weight_teamregistration_locked_weight_and_more.py
  5. 4
      tournaments/models/court.py
  6. 13
      tournaments/models/group_stage.py
  7. 2
      tournaments/models/match.py
  8. 2
      tournaments/models/player_registration.py
  9. 6
      tournaments/models/team_registration.py
  10. 2
      tournaments/models/tournament.py
  11. 1
      tournaments/serializers.py
  12. 1
      tournaments/views.py

@ -42,7 +42,7 @@ class MatchAdmin(admin.ModelAdmin):
list_display = ['__str__', 'round', 'group_stage', 'start_date', 'index'] list_display = ['__str__', 'round', 'group_stage', 'start_date', 'index']
class GroupStageAdmin(admin.ModelAdmin): class GroupStageAdmin(admin.ModelAdmin):
list_display = ['tournament', 'index'] list_display = ['tournament', 'index', 'start_date']
class EventAdmin(admin.ModelAdmin): class EventAdmin(admin.ModelAdmin):
list_display = ['name', 'club', 'creation_date', 'creator'] list_display = ['name', 'club', 'creation_date', 'creator']

@ -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),
),
]

@ -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),
),
]

@ -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),
),
]

@ -7,5 +7,5 @@ class Court(models.Model):
index = models.IntegerField(default=0) index = models.IntegerField(default=0)
club = models.ForeignKey(Club, on_delete=models.CASCADE) club = models.ForeignKey(Club, on_delete=models.CASCADE)
name = models.CharField(max_length=50, null=True, blank=True) name = models.CharField(max_length=50, null=True, blank=True)
#exit_allowed = models.BooleanField(default=False) exit_allowed = models.BooleanField(default=False)
#indoor = models.BooleanField(default=False) indoor = models.BooleanField(default=False)

@ -15,10 +15,13 @@ class GroupStage(models.Model):
name = models.CharField(max_length=200, null=True, blank=True) name = models.CharField(max_length=200, null=True, blank=True)
def __str__(self): def __str__(self):
return f"{self.tournament.display_name()} - {self.name()}" return f"{self.tournament.display_name()} - {self.display_name()}"
def name(self): def display_name(self):
return f"Poule {self.index}" if self.name:
return self.name
else:
return f"Poule {self.index}"
def next_match(self, player_registration): def next_match(self, player_registration):
matches = self.matches_for_registration(player_registration).filter(end_date__isnull=False).order_by('start_date') 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) return [ts.match for ts in team_scores] # map(lambda ts: ts.match, team_scores)
def live_group_stages(self): def live_group_stages(self):
lgs = LiveGroupStage(self.name()) lgs = LiveGroupStage(self.display_name())
gs_teams = {} gs_teams = {}
# init all teams # init all teams
@ -134,7 +137,7 @@ class GroupStageTeam:
self.wins = 0 self.wins = 0
self.losses = 0 self.losses = 0
self.diff = 0 self.diff = 0
self.weight = team_registration.weight() self.weight = team_registration.get_weight()
def wins_losses(self): def wins_losses(self):
return f"{self.wins}/{self.losses}" return f"{self.wins}/{self.losses}"

@ -127,7 +127,7 @@ class Match(models.Model):
image = team_score.team_registration.logo image = team_score.team_registration.logo
names = team_score.team_names() names = team_score.team_names()
scores = team_score.scores_array() 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 is_winner = team_score.team_registration.id == self.winning_team_id
walk_out = team_score.walk_out walk_out = team_score.walk_out
team = Team(image, names, scores, weight, is_winner, walk_out) team = Team(image, names, scores, weight, is_winner, walk_out)

@ -27,7 +27,7 @@ class PlayerRegistration(models.Model):
phone_number = models.CharField(max_length=15, null=True, blank=True) phone_number = models.CharField(max_length=15, null=True, blank=True)
email = models.CharField(max_length=50, 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) computed_rank = models.IntegerField(default=0)

@ -22,9 +22,9 @@ class TeamRegistration(models.Model):
wild_card_bracket = models.BooleanField(default=False) wild_card_bracket = models.BooleanField(default=False)
wild_card_group_stage = models.BooleanField(default=False) wild_card_group_stage = models.BooleanField(default=False)
weight = models.IntegerField(default=0) 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) qualified = models.BooleanField(default=False)
def __str__(self): def __str__(self):
@ -71,7 +71,7 @@ class TeamRegistration(models.Model):
else: else:
return "--" return "--"
def weight(self): def get_weight(self):
top_two_players = self.playerregistration_set.all().order_by('rank')[:2] top_two_players = self.playerregistration_set.all().order_by('rank')[:2]
weight = 0 weight = 0
for player in top_two_players: for player in top_two_players:

@ -70,7 +70,7 @@ class Tournament(models.Model):
if next_match: if next_match:
names = team_registration.team_names() names = team_registration.team_names()
stage = next_match.stage_name() 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) summon = TeamSummon(names, next_match.start_date, weight, stage, team_registration.logo)
summons.append(summon) summons.append(summon)

@ -116,7 +116,6 @@ class RoundSerializer(serializers.ModelSerializer):
class GroupStageSerializer(serializers.ModelSerializer): class GroupStageSerializer(serializers.ModelSerializer):
class Meta: class Meta:
# tournament_id = serializers.PrimaryKeyRelatedField(queryset=Tournament.objects.all())
model = GroupStage model = GroupStage
fields = '__all__' # ['id', 'index', 'tournament_id', 'format'] fields = '__all__' # ['id', 'index', 'tournament_id', 'format']

@ -219,6 +219,7 @@ def user_by_token(request):
class UserViewSet(viewsets.ModelViewSet): class UserViewSet(viewsets.ModelViewSet):
queryset = CustomUser.objects.all() queryset = CustomUser.objects.all()
serializer_class = UserUpdateSerializer serializer_class = UserUpdateSerializer
permission_classes = [] # Users are public whereas the other requests are only for logged users
def get_serializer_class(self): def get_serializer_class(self):
# Use UserSerializer for other actions (e.g., create, retrieve) # Use UserSerializer for other actions (e.g., create, retrieve)

Loading…
Cancel
Save