Skip to content

Commit

Permalink
Avoid handling declared winners if undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
tienne-B committed Sep 15, 2024
1 parent 3e7564b commit 5c2f345
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tabbycat/results/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,20 +744,20 @@ def clean_scoresheet(self, cleaned_data):

else:
if len(totals) == 2:
max_teams = [side for side, total in side_totals.items() if total == max(totals)]
high_point_declared = int(cleaned_data.get(self._fieldname_declared_winner())) in max_teams

# Check that no teams had the same total
if totals[0] == totals[1] and self.declared_winner in ['none', 'high-points']:
self.add_error(None, forms.ValidationError(
_("The total scores for the teams are the same (i.e. a draw)."),
code='draw',
))
elif self.declared_winner in ['high-points', 'tied-points'] and not high_point_declared:
self.add_error(None, forms.ValidationError(
_("The declared winner does not correspond to the team with the highest score."),
code='wrong_winner',
))
elif self.declared_winner in ['high-points', 'tied-points']:
max_teams = [side for side, total in side_totals.items() if total == max(totals)]

if int(cleaned_data.get(self._fieldname_declared_winner())) not in max_teams:
self.add_error(None, forms.ValidationError(
_("The declared winner does not correspond to the team with the highest score."),
code='wrong_winner',
))

elif len(totals) > 2:
for total in set(totals):
Expand Down Expand Up @@ -915,20 +915,20 @@ def clean_scoresheet(self, cleaned_data):

else:
if len(totals) == 2:
max_teams = [side for side, total in side_totals.items() if total == max(totals)]
high_point_declared = int(cleaned_data.get(self._fieldname_declared_winner(adj))) in max_teams

# Check that it was not a draw.
if totals[0] == totals[1] and self.declared_winner in ['none', 'high-points']:
self.add_error(None, forms.ValidationError(
_("The total scores for the teams are the same (i.e. a draw) for adjudicator %(adjudicator)s."),
params={'adjudicator': adj.get_public_name(self.tournament)}, code='draw',
))
elif self.declared_winner in ['high-points', 'tied-points'] and not high_point_declared:
self.add_error(None, forms.ValidationError(
_("The declared winner does not correspond to the team with the highest score for adjudicator %(adjudicator)s."),
params={'adjudicator': adj.get_public_name(self.tournament)}, code='wrong_winner',
))
elif self.declared_winner in ['high-points', 'tied-points']:
max_teams = [side for side, total in side_totals.items() if total == max(totals)]

if int(cleaned_data.get(self._fieldname_declared_winner(adj))) not in max_teams:
self.add_error(None, forms.ValidationError(
_("The declared winner does not correspond to the team with the highest score for adjudicator %(adjudicator)s."),
params={'adjudicator': adj.get_public_name(self.tournament)}, code='wrong_winner',
))

# Check that the margin did not exceed the maximum permissible.
margin = abs(totals[0] - totals[1])
Expand Down

0 comments on commit 5c2f345

Please sign in to comment.