|
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|
|
|
|
|
from django import forms
|
|
|
from django.contrib.auth.forms import PasswordResetForm, ReadOnlyPasswordHashField
|
|
|
+from django.forms.utils import ErrorList
|
|
|
|
|
|
from coin.members.models import Member
|
|
|
|
|
@@ -37,20 +38,18 @@ class MemberCreationForm(forms.ModelForm):
|
|
|
return member
|
|
|
|
|
|
|
|
|
-class MemberChangeForm(forms.ModelForm):
|
|
|
-
|
|
|
+class AbstractMemberChangeForm(forms.ModelForm):
|
|
|
"""
|
|
|
This form was inspired from django.contrib.auth.forms.UserChangeForm
|
|
|
and adapted to coin specificities
|
|
|
"""
|
|
|
- password = ReadOnlyPasswordHashField()
|
|
|
|
|
|
class Meta:
|
|
|
model = Member
|
|
|
fields = '__all__'
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
- super(MemberChangeForm, self).__init__(*args, **kwargs)
|
|
|
+ super(AbstractMemberChangeForm, self).__init__(*args, **kwargs)
|
|
|
f = self.fields.get('user_permissions', None)
|
|
|
if f is not None:
|
|
|
f.queryset = f.queryset.select_related('content_type')
|
|
@@ -66,5 +65,52 @@ class MemberChangeForm(forms.ModelForm):
|
|
|
return self.initial["username"]
|
|
|
|
|
|
|
|
|
+class AdminMemberChangeForm(AbstractMemberChangeForm):
|
|
|
+ password = ReadOnlyPasswordHashField()
|
|
|
+
|
|
|
+
|
|
|
+class SpanError(ErrorList):
|
|
|
+ def __unicode__(self):
|
|
|
+ return self.as_spans()
|
|
|
+ def __str__(self):
|
|
|
+ return self.as_spans()
|
|
|
+ def as_spans(self):
|
|
|
+ if not self: return ''
|
|
|
+ return ''.join(['<span class="error">%s</span>' % e for e in self])
|
|
|
+
|
|
|
+class PersonMemberChangeForm(AbstractMemberChangeForm):
|
|
|
+ """
|
|
|
+ Form use to allow natural person to change their info
|
|
|
+ """
|
|
|
+ class Meta:
|
|
|
+ model = Member
|
|
|
+ fields = ['first_name', 'last_name', 'email', 'nickname',
|
|
|
+ 'home_phone_number', 'mobile_phone_number',
|
|
|
+ 'address', 'postal_code', 'city', 'country']
|
|
|
+
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ super(PersonMemberChangeForm, self).__init__(*args, **kwargs)
|
|
|
+ self.error_class = SpanError
|
|
|
+ for fieldname in self.fields:
|
|
|
+ self.fields[fieldname].help_text = None
|
|
|
+
|
|
|
+
|
|
|
+class OrganizationMemberChangeForm(AbstractMemberChangeForm):
|
|
|
+ """
|
|
|
+ Form use to allow organization to change their info
|
|
|
+ """
|
|
|
+ class Meta:
|
|
|
+ model = Member
|
|
|
+ fields = ['organization_name', 'email', 'nickname',
|
|
|
+ 'home_phone_number', 'mobile_phone_number',
|
|
|
+ 'address', 'postal_code', 'city', 'country']
|
|
|
+
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ super(OrganizationChangeForm, self).__init__(*args, **kwargs)
|
|
|
+ self.error_class = SpanError
|
|
|
+ for fieldname in self.fields:
|
|
|
+ self.fields[fieldname].help_text = None
|
|
|
+
|
|
|
class MemberPasswordResetForm(PasswordResetForm):
|
|
|
pass
|
|
|
+
|