|
@@ -1,32 +1,24 @@
|
|
|
|
|
|
from django import forms
|
|
|
-from django.contrib.auth.forms import ReadOnlyPasswordHashField
|
|
|
+from django.contrib.auth.forms import UserChangeForm, ReadOnlyPasswordHashField
|
|
|
|
|
|
from coin.members.models import Member
|
|
|
|
|
|
|
|
|
class MemberCreationForm(forms.ModelForm):
|
|
|
- password = forms.CharField(label='Password', widget=forms.PasswordInput)
|
|
|
+ """
|
|
|
+ This form was inspired from django.contrib.auth.forms.UserCreationForm
|
|
|
+ and adapted to coin spcificities
|
|
|
+ """
|
|
|
+ username = forms.RegexField(required=False,
|
|
|
+ label="Nom d'utilisateur", max_length=30, regex=r"^[\w.@+-]+$",
|
|
|
+ help_text=u"Laisser vide pour le générer automatiquement à partir du "
|
|
|
+ u"nom et du prénom")
|
|
|
+ password = forms.CharField(required=False, label='Mot de passe', widget=forms.PasswordInput)
|
|
|
|
|
|
class Meta:
|
|
|
model = Member
|
|
|
-
|
|
|
- fieldsets = (
|
|
|
- ('Adhérent', {'fields':(
|
|
|
- 'status',
|
|
|
- 'type',
|
|
|
- ('first_name', 'last_name', 'organization_name'),
|
|
|
- ('entry_date', 'resign_date'))}),
|
|
|
- ('Coordonnées', {'fields':(
|
|
|
- 'email',
|
|
|
- ('home_phone_number', 'mobile_phone_number'),
|
|
|
- 'address',
|
|
|
- ('postal_code', 'city', 'country'))}),
|
|
|
- ('Authentification', {'fields':(
|
|
|
- ('username', 'password'),)}),
|
|
|
- ('Permissions', {'fields':(
|
|
|
- ('is_active', 'is_staff', 'is_superuser', 'date_joined'))})
|
|
|
- )
|
|
|
+ fields = '__all__'
|
|
|
|
|
|
def save(self, commit=True):
|
|
|
"""
|
|
@@ -36,35 +28,33 @@ class MemberCreationForm(forms.ModelForm):
|
|
|
member.set_password(self.cleaned_data["password"])
|
|
|
if commit:
|
|
|
member.member()
|
|
|
-
|
|
|
return member
|
|
|
|
|
|
|
|
|
+
|
|
|
class MemberChangeForm(forms.ModelForm):
|
|
|
+ """
|
|
|
+ This form was inspired from django.contrib.auth.forms.UserChangeForm
|
|
|
+ and adapted to coin spcificities
|
|
|
+ """
|
|
|
password = ReadOnlyPasswordHashField()
|
|
|
|
|
|
class Meta:
|
|
|
model = Member
|
|
|
-
|
|
|
- fieldsets = (
|
|
|
- ('Adhérent', {'fields':(
|
|
|
- 'status',
|
|
|
- 'type',
|
|
|
- ('first_name', 'last_name', 'organization_name'),
|
|
|
- ('entry_date', 'resign_date'))}),
|
|
|
- ('Coordonnées', {'fields':(
|
|
|
- 'email',
|
|
|
- ('home_phone_number', 'mobile_phone_number'),
|
|
|
- 'address',
|
|
|
- ('postal_code', 'city', 'country'))}),
|
|
|
- ('Authentification', {'fields':(
|
|
|
- ('username','password'))}),
|
|
|
- ('Permissions', {'fields':(
|
|
|
- ('is_active', 'is_staff', 'is_superuser'))})
|
|
|
- )
|
|
|
+ fields = '__all__'
|
|
|
+
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ super(MemberChangeForm, self).__init__(*args, **kwargs)
|
|
|
+ f = self.fields.get('user_permissions', None)
|
|
|
+ if f is not None:
|
|
|
+ f.queryset = f.queryset.select_related('content_type')
|
|
|
|
|
|
def clean_password(self):
|
|
|
|
|
|
|
|
|
|
|
|
return self.initial["password"]
|
|
|
+
|
|
|
+ def clean_username(self):
|
|
|
+
|
|
|
+ return self.initial["username"]
|