From b7359f5b3880c2fe0c8ae2031e054b52f666e6d8 Mon Sep 17 00:00:00 2001 From: edpibu Date: Wed, 19 Sep 2018 15:40:53 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Fix=20170:=20Ajout=20d'une=20case=20=C3=A0?= =?UTF-8?q?=20cocher=20pour=20=C3=A9viter=20les=20doublons=20de=20comptes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/forms.py | 16 ++++++++++++++++ users/views.py | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/users/forms.py b/users/forms.py index a6ea70b9..e2339a0d 100644 --- a/users/forms.py +++ b/users/forms.py @@ -375,6 +375,22 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): remove_user_room(self.cleaned_data.get('room')) return +class AdherentCreationForm(AdherentForm): + """Formulaire de création d'un user. + AdherentForm auquel on ajoute une checkbox afin d'éviter les + doublons d'utilisateurs""" + def __init__(self, *args, **kwargs): + super(AdherentCreationForm, self).__init__(*args, **kwargs) + + # Champ permettant d'éviter au maxium les doublons d'utilisateurs + former_user_check_info = _("If you already have an account, please use it. "\ + + "If your lost access to it, please consider "\ + + "using the forgotten password button on the "\ + + "login page or contacting support.") + self.fields['former_user_check'] = forms.BooleanField(required=True, + help_text=former_user_check_info) + self.fields['former_user_check'].label = _("I have not had an account before") + class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): """Formulaire de base d'edition d'un user. Formulaire de base, utilisé diff --git a/users/views.py b/users/views.py index 360e256b..41138ce3 100644 --- a/users/views.py +++ b/users/views.py @@ -100,6 +100,7 @@ from .forms import ( ServiceUserForm, ListRightForm, AdherentForm, + AdherentCreationForm, ClubForm, MassArchiveForm, PassForm, @@ -114,7 +115,7 @@ from .forms import ( def new_user(request): """ Vue de création d'un nouvel utilisateur, envoie un mail pour le mot de passe""" - user = AdherentForm(request.POST or None, user=request.user) + user = AdherentCreationForm(request.POST or None, user=request.user) GTU_sum_up = GeneralOption.get_cached_value('GTU_sum_up') GTU = GeneralOption.get_cached_value('GTU') if user.is_valid(): From 1d107d33f2dfac9bf64ef92f70f66b63a2033acf Mon Sep 17 00:00:00 2001 From: edpibu Date: Wed, 19 Sep 2018 23:24:15 +0200 Subject: [PATCH 2/4] Fixed field creation --- users/forms.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/users/forms.py b/users/forms.py index e2339a0d..65e06715 100644 --- a/users/forms.py +++ b/users/forms.py @@ -379,19 +379,18 @@ class AdherentCreationForm(AdherentForm): """Formulaire de création d'un user. AdherentForm auquel on ajoute une checkbox afin d'éviter les doublons d'utilisateurs""" + + # Champ permettant d'éviter au maxium les doublons d'utilisateurs + former_user_check_info = _("If you already have an account, please use it. "\ + + "If your lost access to it, please consider "\ + + "using the forgotten password button on the "\ + + "login page or contacting support.") + former_user_check = forms.BooleanField(required=True, help_text=former_user_check_info) + former_user_check = _("I have not had an account before") + def __init__(self, *args, **kwargs): super(AdherentCreationForm, self).__init__(*args, **kwargs) - - # Champ permettant d'éviter au maxium les doublons d'utilisateurs - former_user_check_info = _("If you already have an account, please use it. "\ - + "If your lost access to it, please consider "\ - + "using the forgotten password button on the "\ - + "login page or contacting support.") - self.fields['former_user_check'] = forms.BooleanField(required=True, - help_text=former_user_check_info) - self.fields['former_user_check'].label = _("I have not had an account before") - - + class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): """Formulaire de base d'edition d'un user. Formulaire de base, utilisé pour l'edition de self par self ou un cableur. On formate les champs From d0fdf841cf3df4076c57200173b822c9b97bc61a Mon Sep 17 00:00:00 2001 From: edpibu Date: Thu, 20 Sep 2018 08:39:48 +0200 Subject: [PATCH 3/4] Fixed label creation on AdherentCreationForm. Added AdherentEditForm. shell and gpg_fingerprint fields have been moved from AdherentForm to AdherentEditForm. --- users/forms.py | 45 ++++++++++++++++++++++++++++++++------------- users/views.py | 4 ++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/users/forms.py b/users/forms.py index 65e06715..7954895a 100644 --- a/users/forms.py +++ b/users/forms.py @@ -318,9 +318,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): self.fields['room'].label = _("Room") self.fields['room'].empty_label = _("No room") 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): if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'): @@ -340,9 +337,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): 'school', 'comment', 'telephone', - 'room', - 'shell', - 'gpg_fingerprint' + 'room' ] @@ -356,12 +351,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): ) 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( label=_("Force the move?"), initial=False, @@ -386,10 +375,40 @@ class AdherentCreationForm(AdherentForm): + "using the forgotten password button on the "\ + "login page or contacting support.") 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): 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): """Formulaire de base d'edition d'un user. Formulaire de base, utilisé diff --git a/users/views.py b/users/views.py index 41138ce3..77a23878 100644 --- a/users/views.py +++ b/users/views.py @@ -99,8 +99,8 @@ from .forms import ( EditServiceUserForm, ServiceUserForm, ListRightForm, - AdherentForm, AdherentCreationForm, + AdherentEditForm, ClubForm, MassArchiveForm, PassForm, @@ -198,7 +198,7 @@ def edit_info(request, user, userid): si l'id est différent de request.user, vérifie la possession du droit cableur """ if user.is_class_adherent: - user_form = AdherentForm( + user_form = AdherentEditForm( request.POST or None, instance=user.adherent, user=request.user From 2db88d628a3a36267e5373ab496b1c4645421df6 Mon Sep 17 00:00:00 2001 From: edpibu Date: Thu, 20 Sep 2018 10:57:31 +0200 Subject: [PATCH 4/4] Added checkbox for GTU. --- users/forms.py | 9 ++++++++- users/templates/users/user.html | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/users/forms.py b/users/forms.py index 7954895a..525ebb74 100644 --- a/users/forms.py +++ b/users/forms.py @@ -48,6 +48,8 @@ from re2o.utils import remove_user_room, get_input_formats_help_text from re2o.mixins import FormRevMixin from re2o.field_permissions import FieldPermissionFormMixin +from preferences.models import GeneralOption + from .widgets import DateTimePicker from .models import ( @@ -377,13 +379,18 @@ class AdherentCreationForm(AdherentForm): former_user_check = forms.BooleanField(required=True, help_text=former_user_check_info) former_user_check.label = _("I have not had an account before") + # Checkbox for GTU + gtu_check = forms.BooleanField(required=True) + gtu_check.label = mark_safe("{}{}{}".format( + _("I commit to accept the "), GeneralOption.get_cached_value('GTU'), _("General Terms of Use"), _("."))) + def __init__(self, *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): + 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: diff --git a/users/templates/users/user.html b/users/templates/users/user.html index 3f19d3d8..6282c2fa 100644 --- a/users/templates/users/user.html +++ b/users/templates/users/user.html @@ -42,7 +42,6 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %}
{% if showCGU %} -

{% trans "By clicking 'Create or edit', the user commits to respect the " %}{% trans "General Terms of Use" %}.

{% trans "Summary of the General Terms of Use" %}

{{ GTU_sum_up }}

{% endif %}