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