From 194e58419eca1ba5222bdf1c628ad509d0fd8498 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 16 Oct 2023 22:51:31 +0200 Subject: [PATCH] =?UTF-8?q?Modifie=20menu=20saisie=20civilit=C3=A9=20?= =?UTF-8?q?=C3=A9tat=20civil.=20Modifie=20contraintes=20INE/NIP=20en=20bas?= =?UTF-8?q?e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/__init__.py | 6 ++- app/models/etudiants.py | 14 +++--- app/scodoc/sco_etud.py | 16 ++++--- app/scodoc/sco_portal_apogee.py | 7 +-- app/views/scolar.py | 10 ++--- .../497ba81343f7_identite_admission.py | 44 +++++++++++++++++++ 6 files changed, 75 insertions(+), 22 deletions(-) diff --git a/app/models/__init__.py b/app/models/__init__.py index e4c6bd17..c4e04bd6 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -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 diff --git a/app/models/etudiants.py b/app/models/etudiants.py index 432cd5c0..764dbcb9 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -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(): diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 77d445ea..efa00eee 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -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 diff --git a/app/scodoc/sco_portal_apogee.py b/app/scodoc/sco_portal_apogee.py index 8b0205dd..95ad30d9 100644 --- a/app/scodoc/sco_portal_apogee.py +++ b/app/scodoc/sco_portal_apogee.py @@ -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"] = "" diff --git a/app/views/scolar.py b/app/views/scolar.py index fe97332d..c136252a 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -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", }, diff --git a/migrations/versions/497ba81343f7_identite_admission.py b/migrations/versions/497ba81343f7_identite_admission.py index 73b97ec1..aa275ae1 100644 --- a/migrations/versions/497ba81343f7_identite_admission.py +++ b/migrations/versions/497ba81343f7_identite_admission.py @@ -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(