This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
portail-citoyen2/portail_citoyen/forms.py

25 lines
934 B
Python

from django import forms
from django.contrib.auth.forms import UserChangeForm as AuthUserChangeForm, UserCreationForm as AuthUserCreationForm
from django.contrib.auth import get_user_model
from authentic2.forms import UserProfileForm
class UserChangeForm(AuthUserChangeForm):
class Meta(AuthUserChangeForm.Meta):
model = get_user_model()
class UserCreationForm(AuthUserCreationForm):
class Meta(AuthUserCreationForm.Meta):
model = get_user_model()
def clean_username(self):
# Since User.username is unique, this check is redundant,
# but it sets a nicer error message than the ORM. See #13147.
username = self.cleaned_data["username"]
User = get_user_model()
try:
User._default_manager.get(username=username)
except User.DoesNotExist:
return username
raise forms.ValidationError(self.error_messages['duplicate_username'])