diff --git a/kfet/forms.py b/kfet/forms.py index 7826cb41..64c39bb2 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -1,6 +1,7 @@ from decimal import Decimal from django import forms from django.core.exceptions import ValidationError +from django.core.validators import MinLengthValidator from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType from django.forms import modelformset_factory, inlineformset_factory @@ -75,6 +76,12 @@ class CofRestrictForm(CofForm): fields = ['departement'] 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: model = User fields = ['username', 'first_name', 'last_name', 'email'] diff --git a/kfet/views.py b/kfet/views.py index d99d3262..844ed8ce 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -190,6 +190,8 @@ def account_create_ajax(request, username=None, login_clipper=None): user_form = UserForm() cof_form = CofForm() 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", { 'account_form' : account_form,