@@ -141,9 +141,9 @@ def validate(self, data):
141
141
round = data .pop ("round" , 0 )
142
142
matchs = data .pop ("matchs" , [])
143
143
data ["warning" ] = False
144
+ tournament = {f"{ self .match_type } __tournament" : data ["tournament" ]}
144
145
145
146
if round :
146
- tournament = {f"{ self .match_type } __tournament" : data ["tournament" ]}
147
147
if self .match_class .objects .filter (round_number__lt = round , ** tournament ).exclude (status = MatchStatus .COMPLETED ).exists ():
148
148
raise serializers .ValidationError (_ ("Des matchs des tours précédents sont encore en cours ou ne sont pas terminés." ))
149
149
@@ -157,9 +157,20 @@ def validate(self, data):
157
157
data ["matchs" ] = []
158
158
159
159
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 ()
161
167
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 ():
163
174
data ["matchs" ].append (match )
164
175
else :
165
176
data ["warning" ] = True
0 commit comments