mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-07-06 07:23:55 +02:00
Create and join teams forms
This commit is contained in:
@ -1,10 +1,19 @@
|
||||
import re
|
||||
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Team
|
||||
|
||||
|
||||
class TeamForm(forms.ModelForm):
|
||||
def clean_trigram(self):
|
||||
trigram = self.cleaned_data["trigram"].upper()
|
||||
if not re.match("[A-Z]{3}", trigram):
|
||||
raise ValidationError(_("The trigram must be composed of three uppercase letters."))
|
||||
return trigram
|
||||
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = ('name', 'trigram', 'grant_animath_access_videos',)
|
||||
@ -14,13 +23,14 @@ class JoinTeamForm(forms.ModelForm):
|
||||
def clean_access_code(self):
|
||||
access_code = self.cleaned_data["access_code"]
|
||||
if not Team.objects.filter(access_code=access_code).exists():
|
||||
raise ValidationError("No team was found with this access code.")
|
||||
raise ValidationError(_("No team was found with this access code."))
|
||||
return access_code
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
if "access_code" in cleaned_data:
|
||||
self.instance = Team.objects.get(access_code=cleaned_data["access_code"])
|
||||
team = Team.objects.get(access_code=cleaned_data["access_code"])
|
||||
self.instance = team
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
|
Reference in New Issue
Block a user