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

Merge branch 'former_user_checkbox_fix170' into 'dev'

Changed AdherentForm usage and fixed issue #170

See merge request federez/re2o!294
This commit is contained in:
chirac 2018-09-20 14:35:41 +02:00
commit e1c6c84c72
3 changed files with 57 additions and 16 deletions

View file

@ -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 (
@ -318,9 +320,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 +339,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'school',
'comment',
'telephone',
'room',
'shell',
'gpg_fingerprint'
'room'
]
@ -356,12 +353,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,
@ -375,7 +366,57 @@ 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"""
# 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.label = _("I have not had an account before")
# Checkbox for GTU
gtu_check = forms.BooleanField(required=True)
gtu_check.label = mark_safe("{}<a href='/media/{}' download='CGU'>{}</a>{}".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):
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é
pour l'edition de self par self ou un cableur. On formate les champs

View file

@ -42,7 +42,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %}
<br>
{% if showCGU %}
<p>{% trans "By clicking 'Create or edit', the user commits to respect the " %}<a href="/media/{{ GTU }}" download="CGU" >{% trans "General Terms of Use" %}</a>.</p>
<h3>{% trans "Summary of the General Terms of Use" %}</h3>
<p>{{ GTU_sum_up }}</p>
{% endif %}

View file

@ -99,7 +99,8 @@ from .forms import (
EditServiceUserForm,
ServiceUserForm,
ListRightForm,
AdherentForm,
AdherentCreationForm,
AdherentEditForm,
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():
@ -197,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