1
0
forked from ScoDoc/ScoDoc

Modifie menu saisie civilité état civil. Modifie contraintes INE/NIP en base.

This commit is contained in:
Emmanuel Viennet 2023-10-16 22:51:31 +02:00
parent 90b4b4b5d6
commit 194e58419e
6 changed files with 75 additions and 22 deletions

View File

@ -70,7 +70,11 @@ class ScoDocModel:
@classmethod
def convert_dict_fields(cls, args: dict) -> dict:
"Convert fields in the given dict. No side effect."
"""Convert fields in the given dict. No side effect.
By default, do nothing, but is overloaded by some subclasses.
args: dict with args in application.
returns: dict to store in model's db.
"""
# virtual, by default, do nothing
return args

View File

@ -49,10 +49,10 @@ class Identite(db.Model, models.ScoDocModel):
"optionnel (si present, affiché à la place du nom)"
civilite = db.Column(db.String(1), nullable=False)
# données d'état-civil. Si présent remplace les données d'usage dans les documents
# données d'état-civil. Si présent (non null) remplace les données d'usage dans les documents
# officiels (bulletins, PV): voir nomprenom_etat_civil()
civilite_etat_civil = db.Column(db.String(1), nullable=False, server_default="X")
prenom_etat_civil = db.Column(db.Text(), nullable=False, server_default="")
civilite_etat_civil = db.Column(db.String(1), nullable=True)
prenom_etat_civil = db.Column(db.Text(), nullable=True)
date_naissance = db.Column(db.Date)
lieu_naissance = db.Column(db.Text())
@ -313,6 +313,8 @@ class Identite(db.Model, models.ScoDocModel):
def convert_dict_fields(cls, args: dict) -> dict:
"""Convert fields in the given dict. No other side effect.
If required dept_id is not specified, set it to the current dept.
args: dict with args in application.
returns: dict to store in model's db.
"""
fs_uppercase = {"nom", "prenom", "prenom_etat_civil"}
fs_empty_stored_as_nulls = {
@ -698,7 +700,6 @@ def input_civilite(s: str) -> str:
Raises ScoValueError if conversion fails.
"""
if not isinstance(s, str):
breakpoint()
raise ScoValueError("valeur invalide pour la civilité (chaine attendue)")
s = s.upper().strip()
if s in ("M", "M.", "MR", "H"):
@ -837,7 +838,10 @@ class Admission(db.Model, models.ScoDocModel):
@classmethod
def convert_dict_fields(cls, args: dict) -> dict:
"Convert fields in the given dict. No other side effect"
"""Convert fields in the given dict. No other side effect.
args: dict with args in application.
returns: dict to store in model's db.
"""
fs_uppercase = {"bac", "specialite"}
args_dict = {}
for key, value in args.items():

View File

@ -62,8 +62,10 @@ def format_etud_ident(etud):
else:
etud["prenom_etat_civil"] = ""
etud["civilite_str"] = format_civilite(etud["civilite"])
etud["civilite_etat_civil_str"] = format_civilite(
etud.get("civilite_etat_civil", "X")
etud["civilite_etat_civil_str"] = (
format_civilite(etud["civilite_etat_civil"])
if etud["civilite_etat_civil"]
else ""
)
# Nom à afficher:
if etud["nom_usuel"]:
@ -141,8 +143,8 @@ def format_civilite(civilite):
"F": "Mme",
"X": "",
}[civilite]
except KeyError:
raise ScoValueError("valeur invalide pour la civilité: %s" % civilite)
except KeyError as exc:
raise ScoValueError(f"valeur invalide pour la civilité: {civilite}") from exc
def format_etat_civil(etud: dict):
@ -256,7 +258,11 @@ def identite_list(cnx, *a, **kw):
else:
o["annee_naissance"] = o["date_naissance"]
o["civilite_str"] = format_civilite(o["civilite"])
o["civilite_etat_civil_str"] = format_civilite(o["civilite_etat_civil"])
o["civilite_etat_civil_str"] = (
format_civilite(o["civilite_etat_civil"])
if o["civilite_etat_civil"]
else ""
)
return objs

View File

@ -489,7 +489,7 @@ def _normalize_apo_fields(infolist):
recode les champs: paiementinscription (-> booleen), datefinalisationinscription (date)
ajoute le champs 'paiementinscription_str' : 'ok', 'Non' ou '?'
ajoute les champs 'etape' (= None) et 'prenom' ('') s'ils ne sont pas présents.
ajoute le champ 'civilite_etat_civil' (='X'), et 'prenom_etat_civil' (='') si non présent.
ajoute le champ 'civilite_etat_civil' (=''), et 'prenom_etat_civil' (='') si non présent.
"""
for infos in infolist:
if "paiementinscription" in infos:
@ -522,10 +522,7 @@ def _normalize_apo_fields(infolist):
infos["prenom"] = ""
if "civilite_etat_civil" not in infos:
infos["civilite_etat_civil"] = "X"
if "civilite_etat_civil" not in infos:
infos["civilite_etat_civil"] = "X"
infos["civilite_etat_civil"] = ""
if "prenom_etat_civil" not in infos:
infos["prenom_etat_civil"] = ""

View File

@ -582,10 +582,8 @@ def etud_info(etudid=None, fmt="xml"):
"date_naissance_iso",
):
d[a] = etud[a] # ne pas quoter car ElementTree.tostring quote déjà
d["civilite"] = etud["civilite_str"] # exception: ne sort pas la civilite brute
d["civilite_etat_civil"] = etud[
"civilite_etat_civil_str"
] # exception: ne sort pas la civilite brute
d["civilite"] = etud["civilite_str"] # exception: ne sort pas les civilités brutes
d["civilite_etat_civil"] = etud["civilite_etat_civil_str"]
d["sexe"] = d["civilite"] # backward compat pour anciens clients
d["photo_url"] = sco_photos.etud_photo_url(etud)
@ -1472,8 +1470,8 @@ def _etudident_create_or_edit_form(edit):
"civilite_etat_civil",
{
"input_type": "menu",
"labels": ["Homme", "Femme", "Autre/neutre"],
"allowed_values": ["M", "F", "X"],
"labels": ["(identique à civilité)", "Homme", "Femme", "Autre/neutre"],
"allowed_values": ["", "M", "F", "X"],
"title": "Civilité (état-civil)",
"explanation": "Si précisé: remplace la civilité d'usage dans les documents officiels",
},

View File

@ -65,6 +65,30 @@ def upgrade():
)
batch_op.drop_constraint("identite_dept_id_code_ine_key", type_="unique")
batch_op.drop_constraint("identite_dept_id_code_nip_key", type_="unique")
batch_op.create_index(
"unique_dept_ine_except_null",
["dept_id", "code_ine"],
unique=True,
postgresql_where=sa.text("code_ine IS NOT NULL"),
)
batch_op.create_index(
"unique_dept_nip_except_null",
["dept_id", "code_nip"],
unique=True,
postgresql_where=sa.text("code_nip IS NOT NULL"),
)
batch_op.alter_column(
"civilite_etat_civil",
existing_type=sa.VARCHAR(length=1),
nullable=True,
existing_server_default=sa.text("'X'::character varying"),
)
batch_op.alter_column(
"prenom_etat_civil",
existing_type=sa.TEXT(),
nullable=True,
existing_server_default=sa.text("''::text"),
)
with op.batch_alter_table("adresse", schema=None) as batch_op:
batch_op.alter_column("etudid", existing_type=sa.Integer(), nullable=False)
@ -108,6 +132,26 @@ def downgrade():
batch_op.alter_column("boursier", existing_type=sa.BOOLEAN(), nullable=True)
batch_op.alter_column("dept_id", existing_type=sa.Integer(), nullable=True)
batch_op.drop_column("admission_id")
batch_op.drop_index(
"unique_dept_nip_except_null",
postgresql_where=sa.text("code_nip IS NOT NULL"),
)
batch_op.drop_index(
"unique_dept_ine_except_null",
postgresql_where=sa.text("code_ine IS NOT NULL"),
)
batch_op.alter_column(
"prenom_etat_civil",
existing_type=sa.TEXT(),
nullable=False,
existing_server_default=sa.text("''::text"),
)
batch_op.alter_column(
"civilite_etat_civil",
existing_type=sa.VARCHAR(length=1),
nullable=False,
existing_server_default=sa.text("'X'::character varying"),
)
with op.batch_alter_table("admissions", schema=None) as batch_op:
# batch_op.add_column(