Skip to content

Commit 879d0f4

Browse files
committed
raise error if trying to launch a swiss or bracket match with unfinished matchs from previous rounds
1 parent 5a007be commit 879d0f4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

insalan/tournament/serializers.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def validate(self, data):
141141
round = data.pop("round", 0)
142142
matchs = data.pop("matchs", [])
143143
data["warning"] = False
144+
tournament = {f"{self.match_type}__tournament": data["tournament"]}
144145

145146
if round:
146-
tournament = {f"{self.match_type}__tournament": data["tournament"]}
147147
if self.match_class.objects.filter(round_number__lt=round, **tournament).exclude(status=MatchStatus.COMPLETED).exists():
148148
raise serializers.ValidationError(_("Des matchs des tours précédents sont encore en cours ou ne sont pas terminés."))
149149

@@ -157,9 +157,20 @@ def validate(self, data):
157157
data["matchs"] = []
158158

159159
for match in matchs:
160-
ongoing_teams_matchs = self.match_class.objects.filter(teams__in=match.teams.all()).exclude(pk=match.pk).filter(status=MatchStatus.ONGOING)
160+
if self.match_type in ["bracket", "swiss"]:
161+
unfinished_previous_matchs = self.match_class.objects.filter(
162+
round_number__lt=match.round_number,
163+
**tournament, teams__in=match.teams.all()
164+
).exclude(
165+
status=MatchStatus.COMPLETED
166+
).exists()
161167

162-
if not ongoing_teams_matchs.exists():
168+
if unfinished_previous_matchs:
169+
raise serializers.ValidationError(_("Des matchs des tours précédents sont encore en cours ou ne sont pas terminés."))
170+
171+
ongoing_teams_matchs = self.match_class.objects.filter(teams__in=match.teams.all(),status=MatchStatus.ONGOING).exclude(pk=match.pk)
172+
173+
if not ongoing_teams_matchs.exists() and match.teams.all().exists():
163174
data["matchs"].append(match)
164175
else:
165176
data["warning"] = True

0 commit comments

Comments
 (0)