8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Fixed label creation on AdherentCreationForm. Added AdherentEditForm. shell and gpg_fingerprint fields have been moved from AdherentForm to AdherentEditForm.

This commit is contained in:
edpibu 2018-09-20 08:39:48 +02:00 committed by chirac
parent 1d107d33f2
commit d0fdf841cf
2 changed files with 34 additions and 15 deletions

View file

@ -318,9 +318,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['room'].label = _("Room") self.fields['room'].label = _("Room")
self.fields['room'].empty_label = _("No room") self.fields['room'].empty_label = _("No room")
self.fields['school'].empty_label = _("Select a school") self.fields['school'].empty_label = _("Select a school")
self.fields['gpg_fingerprint'].widget.attrs['placeholder'] = _("Leave empty if you don't have any GPG key.")
if 'shell' in self.fields:
self.fields['shell'].empty_label = _("Default shell")
def clean_email(self): def clean_email(self):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'): if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
@ -340,9 +337,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'school', 'school',
'comment', 'comment',
'telephone', 'telephone',
'room', 'room'
'shell',
'gpg_fingerprint'
] ]
@ -356,12 +351,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
) )
return telephone return telephone
def clean_gpg_fingerprint(self):
"""Format the GPG fingerprint"""
gpg_fingerprint = self.cleaned_data.get('gpg_fingerprint', None)
if gpg_fingerprint:
return gpg_fingerprint.replace(' ', '').upper()
force = forms.BooleanField( force = forms.BooleanField(
label=_("Force the move?"), label=_("Force the move?"),
initial=False, initial=False,
@ -386,10 +375,40 @@ class AdherentCreationForm(AdherentForm):
+ "using the forgotten password button on the "\ + "using the forgotten password button on the "\
+ "login page or contacting support.") + "login page or contacting support.")
former_user_check = forms.BooleanField(required=True, help_text=former_user_check_info) former_user_check = forms.BooleanField(required=True, help_text=former_user_check_info)
former_user_check = _("I have not had an account before") former_user_check.label = _("I have not had an account before")
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(AdherentCreationForm, self).__init__(*args, **kwargs) super(AdherentCreationForm, self).__init__(*args, **kwargs)
class AdherentEditForm(AdherentForm):
"""Formulaire d'édition d'un user.
AdherentForm incluant la modification des champs gpg et shell"""
def __init__(self, *args, **kargs):
super(AdherentEditForm, self).__init__(*args, **kwargs)
self.fields['gpg_fingerprint'].widget.attrs['placeholder'] = _("Leave empty if you don't have any GPG key.")
if 'shell' in self.fields:
self.fields['shell'].empty_label = _("Default shell")
def clean_gpg_fingerprint(self):
"""Format the GPG fingerprint"""
gpg_fingerprint = self.cleaned_data.get('gpg_fingerprint', None)
if gpg_fingerprint:
return gpg_fingerprint.replace(' ', '').upper()
class Meta:
model = Adherent
fields = [
'name',
'surname',
'pseudo',
'email',
'school',
'comment',
'telephone',
'room',
'shell',
'gpg_fingerprint'
]
class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Formulaire de base d'edition d'un user. Formulaire de base, utilisé """Formulaire de base d'edition d'un user. Formulaire de base, utilisé

View file

@ -99,8 +99,8 @@ from .forms import (
EditServiceUserForm, EditServiceUserForm,
ServiceUserForm, ServiceUserForm,
ListRightForm, ListRightForm,
AdherentForm,
AdherentCreationForm, AdherentCreationForm,
AdherentEditForm,
ClubForm, ClubForm,
MassArchiveForm, MassArchiveForm,
PassForm, PassForm,
@ -198,7 +198,7 @@ def edit_info(request, user, userid):
si l'id est différent de request.user, vérifie la si l'id est différent de request.user, vérifie la
possession du droit cableur """ possession du droit cableur """
if user.is_class_adherent: if user.is_class_adherent:
user_form = AdherentForm( user_form = AdherentEditForm(
request.POST or None, request.POST or None,
instance=user.adherent, instance=user.adherent,
user=request.user user=request.user