forked from DGNum/gestioCOF
Nouveau compte fix
- Pour un compte qui n'est pas du tout déjà présent dans la BDD, username doit faire 9 caractères minimum (ty @mpepin) et le champ cof et login clipper ne sont plus modifiables
This commit is contained in:
parent
42cca8f9cf
commit
7ea0998bdb
2 changed files with 9 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.validators import MinLengthValidator
|
||||||
from django.contrib.auth.models import User, Group, Permission
|
from django.contrib.auth.models import User, Group, Permission
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.forms import modelformset_factory, inlineformset_factory
|
from django.forms import modelformset_factory, inlineformset_factory
|
||||||
|
@ -75,6 +76,12 @@ class CofRestrictForm(CofForm):
|
||||||
fields = ['departement']
|
fields = ['departement']
|
||||||
|
|
||||||
class UserForm(forms.ModelForm):
|
class UserForm(forms.ModelForm):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
new_user = kwargs.get('instance') is None
|
||||||
|
super(UserForm, self).__init__(*args, **kwargs)
|
||||||
|
if new_user:
|
||||||
|
self.fields['username'].validators = [MinLengthValidator(9)]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['username', 'first_name', 'last_name', 'email']
|
fields = ['username', 'first_name', 'last_name', 'email']
|
||||||
|
|
|
@ -190,6 +190,8 @@ def account_create_ajax(request, username=None, login_clipper=None):
|
||||||
user_form = UserForm()
|
user_form = UserForm()
|
||||||
cof_form = CofForm()
|
cof_form = CofForm()
|
||||||
account_form = AccountNoTriForm()
|
account_form = AccountNoTriForm()
|
||||||
|
cof_form.fields['login_clipper'].widget.attrs['readonly'] = True
|
||||||
|
cof_form.fields['is_cof'].widget.attrs['disabled'] = True
|
||||||
|
|
||||||
return render(request, "kfet/account_create_form.html", {
|
return render(request, "kfet/account_create_form.html", {
|
||||||
'account_form' : account_form,
|
'account_form' : account_form,
|
||||||
|
|
Loading…
Reference in a new issue