mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 16:02:26 +01:00 
			
		
		
		
	Team trigrams and names are unique
This commit is contained in:
		@@ -17,11 +17,22 @@ class TeamForm(forms.ModelForm):
 | 
			
		||||
    """
 | 
			
		||||
    Form to create a team, with the name and the trigram,...
 | 
			
		||||
    """
 | 
			
		||||
    def clean_name(self):
 | 
			
		||||
        if "name" in self.cleaned_data:
 | 
			
		||||
            name = self.cleaned_data["name"].upper()
 | 
			
		||||
            if not self.instance.pk and Team.objects.filter(name=name).exists():
 | 
			
		||||
                raise ValidationError(_("This name is already used."))
 | 
			
		||||
            return name
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        if "trigram" in self.cleaned_data:
 | 
			
		||||
            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."))
 | 
			
		||||
 | 
			
		||||
            if not self.instance.pk and Team.objects.filter(trigram=trigram).exists():
 | 
			
		||||
                raise ValidationError(_("This trigram is already used."))
 | 
			
		||||
            return trigram
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = Team
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user