Prevent creating club when there exists an alias that is similar to the name of the club

This commit is contained in:
Yohann D'ANELLO 2020-07-28 23:16:38 +02:00
parent 3a4145e4d9
commit f597b6dbd8
1 changed files with 10 additions and 1 deletions

View File

@ -5,7 +5,7 @@ from django import forms
from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from note.models import NoteSpecial from note.models import NoteSpecial, Alias
from note_kfet.inputs import Autocomplete, AmountInput, DatePickerInput from note_kfet.inputs import Autocomplete, AmountInput, DatePickerInput
from permission.models import PermissionMask, Role from permission.models import PermissionMask, Role
@ -38,6 +38,15 @@ class ProfileForm(forms.ModelForm):
class ClubForm(forms.ModelForm): class ClubForm(forms.ModelForm):
def clean(self):
cleaned_data = super().clean()
if not self.instance.pk: # Creating a club
if Alias.objects.filter(normalized_name=Alias.normalize(self.cleaned_data["name"])).exists():
self.add_error('name', _("An alias with a similar name already exists."))
return cleaned_data
class Meta: class Meta:
model = Club model = Club
fields = '__all__' fields = '__all__'