From 7e532ae04db76addb0a7b8965d54dd6ebedf9239 Mon Sep 17 00:00:00 2001 From: Jean-Pascal Milcent <51449363+jpm-cbna@users.noreply.github.com> Date: Thu, 22 Jun 2023 14:57:47 +0200 Subject: [PATCH] Fix various: when null value for organism or role name (#126) * Fix info_user: display user without organism Fix #125. Fix t_roles: accept user first or last name null Fix #107. * Full name when nom or prenom is null --------- Co-authored-by: amandine-sahl --- app/genericRepository.py | 10 ++++++---- app/models.py | 7 +------ app/t_roles/route.py | 23 +++++++++++++---------- app/templates/info_user.html | 6 +++--- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/genericRepository.py b/app/genericRepository.py index 947edee2..ab59e607 100644 --- a/app/genericRepository.py +++ b/app/genericRepository.py @@ -11,18 +11,20 @@ class GenericRepository(db.Model): @classmethod def get_one(cls, id, as_model=False): - """ Methode qui retourne un dictionnaire d'un élément d'un Model Avec pour paramètres l'id de l'élément Si as_model != False alors au lieu de retourner un dictionnaire on retourne l'object du modèle """ + if not id: + return None + + data = db.session.query(cls).get(id) - if as_model == False: - data = db.session.query(cls).get(id) + if not as_model: return data.as_dict(True) else: - return db.session.query(cls).get(id) + return data @classmethod def get_all( diff --git a/app/models.py b/app/models.py index cf04e52e..e867b2f1 100644 --- a/app/models.py +++ b/app/models.py @@ -194,12 +194,7 @@ def get_full_name(self): Methode qui concatène le nom et prénom du role retourne un nom complet """ - - if self.prenom_role == None: - full_name = self.nom_role - else: - full_name = self.nom_role + " " + self.prenom_role - return full_name + return ' '.join([(self.nom_role or ''), (self.prenom_role or '')]) def as_dict_full_name(self): """ diff --git a/app/t_roles/route.py b/app/t_roles/route.py index 8dc27dca..4f22d505 100644 --- a/app/t_roles/route.py +++ b/app/t_roles/route.py @@ -219,6 +219,9 @@ def updatepass(id_role=None): """ form = t_rolesforms.UserPass() myuser = TRoles.get_one(id_role) + # Build title + role_fullname= buildUserFullName(myuser) + title=f"Changer le mot de passe de l'utilisateur '{role_fullname}'" if request.method == "POST": if form.validate_on_submit() and form.validate(): @@ -241,11 +244,7 @@ def updatepass(id_role=None): return render_template( "user_pass.html", form=form, - title="Changer le mot de passe de l'utilisateur '" - + myuser["nom_role"] - + " " - + myuser["prenom_role"] - + "'", + title=title, id_role=id_role, ) form_user["id_role"] = id_role @@ -257,11 +256,7 @@ def updatepass(id_role=None): return render_template( "user_pass.html", form=form, - title="Changer le mot de passe de l'utilisateur '" - + myuser["nom_role"] - + " " - + myuser["prenom_role"] - + "'", + title=title, id_role=id_role, ) @@ -300,6 +295,14 @@ def info(id_role): pathU=URL_APPLICATION + "/user/update/", ) +def buildUserFullName(user): + fullname = [] + if user["nom_role"]: + fullname.append(user["nom_role"].upper()) + if user["prenom_role"]: + fullname.append(user["prenom_role"].title()) + return ' '.join(fullname) + def pops(form, with_group=True): """ diff --git a/app/templates/info_user.html b/app/templates/info_user.html index 0ada3614..eb1f317d 100644 --- a/app/templates/info_user.html +++ b/app/templates/info_user.html @@ -3,7 +3,7 @@ {%set is_identifiant = user['identifiant'] is not none and user['identifiant'] != '' %} {%set is_uuid = user['uuid_role'] is not none and user['uuid_role'] != '' %} -{%set is_organisme = organisme.nom_organisme is not none and organisme.nom_organisme != '' %} +{%set is_organisme = organisme is not none and organisme['nom_organisme'] != '' %} {%set is_desc = user['desc_role'] is not none and user['desc_role'] != '' %} {%set is_remarques = user['remarques'] is not none and user['remarques'] != '' %} {%set is_mail = user['email'] is not none and user['email'] != '' %} @@ -11,7 +11,7 @@ {%set is_list = lists|length > 0 %} {%set is_right = rights|length > 0 %}
-

Utilisateur "{{user['nom_role']}} {{user['prenom_role']}}"

+

Utilisateur "{{user['fullname']}}"

{% if is_desc %} @@ -21,7 +21,7 @@

Utilisateur "{{user['nom_role']}} {{user['prenom_role']}}"


UUID : {{user['uuid_role']}} {% endif %} {% if is_identifiant %} -
Identifiant :{{user['identifiant']}} +
Identifiant : {{user['identifiant']}} {% endif %} {% if is_mail %}
Email : {{user['email']}}