mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-07-06 20:54:01 +02:00
Display popups to create and join team
This commit is contained in:
28
apps/participation/forms.py
Normal file
28
apps/participation/forms.py
Normal file
@ -0,0 +1,28 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .models import Team
|
||||
|
||||
|
||||
class TeamForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = ('name', 'trigram', 'grant_animath_access_videos',)
|
||||
|
||||
|
||||
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.")
|
||||
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"])
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = ('access_code',)
|
Reference in New Issue
Block a user