From a904db9eee6ff3ff048af6d6996db23f9c027e4d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 23 Aug 2024 04:30:53 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20synchro=20etud,=20unicit=C3=A9=20codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/etudiants.py | 8 +-- app/scodoc/sco_import_etuds.py | 10 ++-- app/views/scolar.py | 95 +++++++++++++++------------------- 3 files changed, 53 insertions(+), 60 deletions(-) diff --git a/app/models/etudiants.py b/app/models/etudiants.py index e64bbbb8..9bb6cc56 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -260,8 +260,8 @@ class Identite(models.ScoDocModel): Add to session but don't commit. True if modification. """ - check_etud_duplicate_code(args, "code_nip") - check_etud_duplicate_code(args, "code_ine") + check_etud_duplicate_code(args, "code_nip", etudid=self.id) + check_etud_duplicate_code(args, "code_ine", etudid=self.id) return super().from_dict(args, **kwargs) @classmethod @@ -796,11 +796,11 @@ class Identite(models.ScoDocModel): ) -def check_etud_duplicate_code(args, code_name, edit=True): +def check_etud_duplicate_code(args, code_name, edit=True, etudid: int | None = None): """Vérifie que le code n'est pas dupliqué. Raises ScoGenError si problème. """ - etudid = args.get("etudid", None) + etudid = etudid or args.get("etudid", None) if not args.get(code_name, None): return etuds = Identite.query.filter_by( diff --git a/app/scodoc/sco_import_etuds.py b/app/scodoc/sco_import_etuds.py index 48244246..e3f413e3 100644 --- a/app/scodoc/sco_import_etuds.py +++ b/app/scodoc/sco_import_etuds.py @@ -743,17 +743,21 @@ def scolars_import_admission( # Type admission: traitement particulier if not cur_adm["type_admission"] and not args.get("type_admission"): args["type_admission"] = type_admission - sco_etud.etudident_edit(cnx, args, disable_notify=True) + sco_etud.etudident_edit( # TODO utiliser modèle + cnx, args, disable_notify=True + ) adr = sco_etud.adresse_list(cnx, args={"etudid": etud["etudid"]}) if adr: args["adresse_id"] = adr[0]["adresse_id"] - sco_etud.adresse_edit( + sco_etud.adresse_edit( # TODO utiliser modèle cnx, args, disable_notify=True ) # pas de notification ici else: args["typeadresse"] = "domicile" args["description"] = "(infos admission)" - adresse_id = sco_etud.adresse_create(cnx, args) + adresse_id = sco_etud.adresse_create( # TODO utiliser modèle + cnx, args + ) # log('import_adm: %s' % args ) # Change les groupes si nécessaire: if "groupes" in args: diff --git a/app/views/scolar.py b/app/views/scolar.py index a681b8e1..6b347e40 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -55,6 +55,7 @@ from app.decorators import ( permission_required_compat_scodoc7, ) from app.models import ( + Adresse, Admission, Departement, FormSemestre, @@ -1974,7 +1975,6 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False): members, group, _, sem, _ = sco_groups.get_group_infos(group_id, etat=etat) formsemestre_id = group["formsemestre_id"] - cnx = ndb.GetDBConnexion() H = [ html_sco_header.html_sem_header( "Étudiants du %s" % (group["group_name"] or "semestre") @@ -1996,10 +1996,10 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False): ) infos = sco_portal_apogee.get_infos_apogee(nom, prenom) if not infos: - info_apogee = ( - 'Pas d\'information (Modifier identité)' - % etudid - ) + info_apogee = f"""Pas d'information + (Modifier identité)""" nerrs += 1 else: if len(infos) == 1: @@ -2007,24 +2007,24 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False): if code_nip != nip_apogee: if fix: # Update database - sco_etud.identite_edit( - cnx, - args={"etudid": etudid, "code_nip": nip_apogee}, - ) + etud = Identite.get_etud(etudid) + etud.code_nip = nip_apogee + db.session.add(etud) + db.session.commit() info_apogee = ( - 'copié %s' % nip_apogee + f'copié {nip_apogee}' ) nfix += 1 else: - info_apogee = '%s' % nip_apogee + info_apogee = f'{nip_apogee}' nerrs += 1 else: info_apogee = "ok" else: - info_apogee = ( - '%d correspondances (Choisir)' - % (len(infos), etudid) - ) + info_apogee = f"""{len(infos)} correspondances + (Choisir)""" nerrs += 1 # check mail if email: @@ -2032,28 +2032,29 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False): else: if fixmail and len(infos) == 1 and "mail" in infos[0]: mail_apogee = infos[0]["mail"] - adrs = sco_etud.adresse_list(cnx, {"etudid": etudid}) - if adrs: - adr = adrs[0] # modif adr existante - args = {"adresse_id": adr["adresse_id"], "email": mail_apogee} - sco_etud.adresse_edit(cnx, args=args, disable_notify=True) + etud = Identite.get_etud(etudid) + adresse = etud.adresse + if adresse: + # modif adr existante + adresse.email = mail_apogee else: # creation adresse - args = {"etudid": etudid, "email": mail_apogee} - sco_etud.adresse_create(cnx, args=args) + adresse = Adresse(etudid=etudid, email=mail_apogee) + db.session.add(adresse) + db.session.commit() mailstat = 'copié' else: mailstat = "inconnu" nmailmissing += 1 H.append( - '%s%s%s%s%s%s' + '%s%s%s%s%s%s' % ( url_for("scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid), nom, nom_usuel, prenom, mailstat, - code_nip, + code_nip or "-", info_apogee, ) ) @@ -2065,42 +2066,30 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False): H.append("
  • Adresse mail: %d étudiants sans adresse
  • " % nmailmissing) H.append("") H.append( - """ -
    - - - + f""" +
    + + + + -

    Retour au semestre - """ - % ( - request.base_url, - formsemestre_id, - scu.strnone(group_id), - scu.strnone(etat), - formsemestre_id, - ) - ) - H.append( - """ -

    - - - +
    + +
    + + + + -

    Retour au semestre +

    + Retour au semestre """ - % ( - request.base_url, - formsemestre_id, - scu.strnone(group_id), - scu.strnone(etat), - formsemestre_id, - ) ) return "\n".join(H) + html_sco_header.sco_footer()