forked from ScoDoc/ScoDoc
Fix: identite.etat_civil
This commit is contained in:
parent
2d3490e7fa
commit
a0316c22e7
@ -284,14 +284,13 @@ class Identite(db.Model, models.ScoDocModel):
|
|||||||
def nomprenom(self, reverse=False) -> str:
|
def nomprenom(self, reverse=False) -> str:
|
||||||
"""Civilité/nom/prenom pour affichages: "M. Pierre Dupont"
|
"""Civilité/nom/prenom pour affichages: "M. Pierre Dupont"
|
||||||
Si reverse, "Dupont Pierre", sans civilité.
|
Si reverse, "Dupont Pierre", sans civilité.
|
||||||
|
Prend l'identité courant et non celle de l'état civile si elles diffèrent.
|
||||||
"""
|
"""
|
||||||
nom = self.nom_usuel or self.nom
|
nom = self.nom_usuel or self.nom
|
||||||
prenom = self.prenom_str
|
prenom = self.prenom_str
|
||||||
if reverse:
|
if reverse:
|
||||||
fields = (nom, prenom)
|
return f"{nom} {prenom}".strip()
|
||||||
else:
|
return f"{self.civilite_str} {prenom} {nom}".strip()
|
||||||
fields = (self.civilite_str, prenom, nom)
|
|
||||||
return " ".join([x for x in fields if x])
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def prenom_str(self):
|
def prenom_str(self):
|
||||||
@ -307,12 +306,10 @@ class Identite(db.Model, models.ScoDocModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def etat_civil(self) -> str:
|
def etat_civil(self) -> str:
|
||||||
"M. Prénom NOM, utilisant les données état civil si présentes, usuelles sinon."
|
"M. PRÉNOM NOM, utilisant les données état civil si présentes, usuelles sinon."
|
||||||
if self.prenom_etat_civil:
|
return f"""{self.civilite_etat_civil_str} {
|
||||||
civ = {"M": "M.", "F": "Mme", "X": ""}[self.civilite_etat_civil]
|
self.prenom_etat_civil or self.prenom or ''} {
|
||||||
return f"{civ} {self.prenom_etat_civil} {self.nom}"
|
self.nom or ''}""".strip()
|
||||||
else:
|
|
||||||
return self.nomprenom
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nom_short(self):
|
def nom_short(self):
|
||||||
|
@ -47,6 +47,7 @@ def test_identite(test_client):
|
|||||||
assert e.prenom == "PRENOM"
|
assert e.prenom == "PRENOM"
|
||||||
assert e.prenom_etat_civil == "PRENOM_ETAT_CIVIL"
|
assert e.prenom_etat_civil == "PRENOM_ETAT_CIVIL"
|
||||||
assert e.dept_naissance == "dept_naissance"
|
assert e.dept_naissance == "dept_naissance"
|
||||||
|
assert e.etat_civil == "PRENOM_ETAT_CIVIL NOM"
|
||||||
#
|
#
|
||||||
admission_id = e.admission_id
|
admission_id = e.admission_id
|
||||||
admission = db.session.get(Admission, admission_id)
|
admission = db.session.get(Admission, admission_id)
|
||||||
@ -81,32 +82,32 @@ def test_etat_civil(test_client):
|
|||||||
dept = Departement.query.first()
|
dept = Departement.query.first()
|
||||||
args = {"nom": "nom", "prenom": "prénom", "civilite": "M", "dept_id": dept.id}
|
args = {"nom": "nom", "prenom": "prénom", "civilite": "M", "dept_id": dept.id}
|
||||||
# Homme
|
# Homme
|
||||||
e = Identite(**args)
|
e = Identite.create_etud(**args)
|
||||||
db.session.add(e)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
assert e.civilite_etat_civil_str == "M."
|
assert e.civilite_etat_civil_str == "M."
|
||||||
assert e.e == ""
|
assert e.e == ""
|
||||||
|
assert e.etat_civil == "M. PRÉNOM NOM"
|
||||||
# Femme
|
# Femme
|
||||||
e = Identite(**args | {"civilite": "F"})
|
e = Identite.create_etud(**args | {"civilite": "F"})
|
||||||
db.session.add(e)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
assert e.civilite_etat_civil_str == "Mme"
|
assert e.civilite_etat_civil_str == "Mme"
|
||||||
assert e.e == "e"
|
assert e.e == "e"
|
||||||
|
assert e.etat_civil == "Mme PRÉNOM NOM"
|
||||||
# Homme devenu femme
|
# Homme devenu femme
|
||||||
e = Identite(**(args | {"civilite_etat_civil": "F"}))
|
e = Identite.create_etud(**(args | {"civilite_etat_civil": "F"}))
|
||||||
db.session.add(e)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
assert e.civilite_etat_civil_str == "Mme"
|
assert e.civilite_etat_civil_str == "Mme"
|
||||||
assert e.civilite_str == "M."
|
assert e.civilite_str == "M."
|
||||||
assert e.e == ""
|
assert e.e == ""
|
||||||
|
assert e.etat_civil == "Mme PRÉNOM NOM"
|
||||||
# Femme devenue neutre
|
# Femme devenue neutre
|
||||||
e = Identite(**(args | {"civilite": "X", "civilite_etat_civil": "F"}))
|
e = Identite.create_etud(**(args | {"civilite": "X", "civilite_etat_civil": "F"}))
|
||||||
db.session.add(e)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
assert e.civilite_etat_civil_str == "Mme"
|
assert e.civilite_etat_civil_str == "Mme"
|
||||||
assert e.civilite_str == ""
|
assert e.civilite_str == ""
|
||||||
assert e.e == "(e)"
|
assert e.e == "(e)"
|
||||||
assert e.prenom_etat_civil is None
|
assert e.prenom_etat_civil is None
|
||||||
|
assert e.etat_civil == "Mme PRÉNOM NOM"
|
||||||
# La version dict
|
# La version dict
|
||||||
e_d = e.to_dict_scodoc7()
|
e_d = e.to_dict_scodoc7()
|
||||||
assert e_d["civilite"] == "X"
|
assert e_d["civilite"] == "X"
|
||||||
@ -119,7 +120,7 @@ def test_etud_legacy(test_client):
|
|||||||
dept = Departement.query.first()
|
dept = Departement.query.first()
|
||||||
args = {"nom": "nom", "prenom": "prénom", "civilite": "M", "dept_id": dept.id}
|
args = {"nom": "nom", "prenom": "prénom", "civilite": "M", "dept_id": dept.id}
|
||||||
# Prénom état civil
|
# Prénom état civil
|
||||||
e = Identite(**(args))
|
e = Identite.create_etud(**(args))
|
||||||
db.session.add(e)
|
db.session.add(e)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
e_dict = e.to_dict_bul()
|
e_dict = e.to_dict_bul()
|
||||||
|
Loading…
Reference in New Issue
Block a user