plateforme-tfjm2/apps/tournament/forms.py

62 lines
1.6 KiB
Python

from django import forms
from django.utils.translation import gettext_lazy as _
from member.models import TFJMUser, Solution, Synthesis
from tfjm.inputs import DatePickerInput, DateTimePickerInput, AmountInput
from tournament.models import Tournament, Team
class TournamentForm(forms.ModelForm):
class Meta:
model = Tournament
fields = '__all__'
widgets = {
"price": AmountInput(),
"date_start": DatePickerInput(),
"date_end": DatePickerInput(),
"date_inscription": DateTimePickerInput(),
"date_solutions": DateTimePickerInput(),
"date_syntheses": DateTimePickerInput(),
}
class OrganizerForm(forms.ModelForm):
class Meta:
model = TFJMUser
fields = ('last_name', 'first_name', 'email', 'is_superuser',)
def save(self, commit=True):
user = self.instance
user.role = '0admin' if user.is_superuser else '1organizer'
super().save(commit)
class TeamForm(forms.ModelForm):
class Meta:
model = Team
fields = ('name', 'trigram', 'tournament',)
class JoinTeam(forms.Form):
access_code = forms.CharField(
label=_("Access code"),
max_length=6,
)
class SolutionForm(forms.ModelForm):
problem = forms.ChoiceField(
label=_("Problem"),
choices=[(str(i), _("Problem #{problem:d}").format(problem=i)) for i in range(1, 9)],
)
class Meta:
model = Solution
fields = ('file', 'problem',)
class SynthesisForm(forms.ModelForm):
class Meta:
model = Synthesis
fields = ('file', 'dest',)