1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-07-04 07:32:18 +02:00

Display detail about a passage

This commit is contained in:
Yohann D'ANELLO
2021-01-14 15:59:11 +01:00
parent f3f862c1ab
commit d912c8aab4
7 changed files with 178 additions and 13 deletions

View File

@ -9,7 +9,7 @@ from django.core.exceptions import ValidationError
from django.utils import formats
from django.utils.translation import gettext_lazy as _
from .models import Participation, Team, Tournament, Solution, Pool
from .models import Participation, Passage, Pool, Team, Tournament, Solution
class TeamForm(forms.ModelForm):
@ -145,3 +145,20 @@ class PoolTeamsForm(forms.ModelForm):
widgets = {
"participations": forms.CheckboxSelectMultiple,
}
class PassageForm(forms.ModelForm):
def clean(self):
cleaned_data = super().clean()
if "defender" in cleaned_data and "opponent" in cleaned_data and "reporter" in cleaned_data \
and len({cleaned_data["defender"], cleaned_data["opponent"], cleaned_data["reporter"]}) < 3:
self.add_error(None, _("The defender, the opponent and the reporter must be different."))
if "defender" in self.cleaned_data and "solution_number" in self.cleaned_data \
and not Solution.objects.filter(participation=cleaned_data["defender"],
problem=cleaned_data["solution_number"]).exists():
self.add_error("solution_number", _("This defender did not work on this problem."))
return cleaned_data
class Meta:
model = Passage
fields = ('solution_number', 'place', 'defender', 'opponent', 'reporter',)