Skip to content

Commit

Permalink
Fix various: when null value for organism or role name (#126)
Browse files Browse the repository at this point in the history
* 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 <amandine.sahl@cevennes-parcnational.fr>
  • Loading branch information
jpm-cbna and amandine-sahl authored Jun 22, 2023
1 parent 4fa9923 commit 7e532ae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
10 changes: 6 additions & 4 deletions app/genericRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 1 addition & 6 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
23 changes: 13 additions & 10 deletions app/t_roles/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -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,
)

Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions app/templates/info_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

{%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'] != '' %}
{%set is_group = groups|length > 0 %}
{%set is_list = lists|length > 0 %}
{%set is_right = rights|length > 0 %}
<div class="container main-zone ng-scope ">
<h3>Utilisateur "{{user['nom_role']}} {{user['prenom_role']}}"</h3>
<h3>Utilisateur "{{user['fullname']}}"</h3>
<div class="ml-5">
<small>
{% if is_desc %}
Expand All @@ -21,7 +21,7 @@ <h3>Utilisateur "{{user['nom_role']}} {{user['prenom_role']}}"</h3>
<br /><strong>UUID :</strong> {{user['uuid_role']}}
{% endif %}
{% if is_identifiant %}
<br /><strong>Identifiant :</strong>{{user['identifiant']}}
<br /><strong>Identifiant :</strong> {{user['identifiant']}}
{% endif %}
{% if is_mail %}
<br /><strong>Email :</strong> <a href="mailto:{{user['email']}}">{{user['email']}}</a>
Expand Down

0 comments on commit 7e532ae

Please sign in to comment.