c836f642fa
This avoid the weird double username situation where we want to give the users the choice of their displayed name but at the same time we need them to never change their CAS username. Now CAS matches on email so we do not have problems.
19 lines
579 B
Python
19 lines
579 B
Python
from django.forms import ModelForm, ValidationError
|
|
from .models import User
|
|
|
|
|
|
class AccountSettingsForm(ModelForm):
|
|
class Meta:
|
|
model = User
|
|
fields = ["public_name"]
|
|
|
|
def clean_public_name(self):
|
|
public_name = self.cleaned_data["public_name"]
|
|
public_name = public_name.strip()
|
|
if (
|
|
User.objects.filter(public_name=public_name)
|
|
.exclude(pk=self.instance.pk)
|
|
.exists()
|
|
):
|
|
raise ValidationError("Un autre compte utilise déjà ce nom ou ce pseudo.")
|
|
return public_name
|