Fix: synchro etud, unicité codes

This commit is contained in:
Emmanuel Viennet 2024-08-23 04:30:53 +02:00
parent 20bb9cc9ed
commit a904db9eee
3 changed files with 53 additions and 60 deletions

View File

@ -260,8 +260,8 @@ class Identite(models.ScoDocModel):
Add to session but don't commit. Add to session but don't commit.
True if modification. True if modification.
""" """
check_etud_duplicate_code(args, "code_nip") check_etud_duplicate_code(args, "code_nip", etudid=self.id)
check_etud_duplicate_code(args, "code_ine") check_etud_duplicate_code(args, "code_ine", etudid=self.id)
return super().from_dict(args, **kwargs) return super().from_dict(args, **kwargs)
@classmethod @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é. """Vérifie que le code n'est pas dupliqué.
Raises ScoGenError si problème. Raises ScoGenError si problème.
""" """
etudid = args.get("etudid", None) etudid = etudid or args.get("etudid", None)
if not args.get(code_name, None): if not args.get(code_name, None):
return return
etuds = Identite.query.filter_by( etuds = Identite.query.filter_by(

View File

@ -743,17 +743,21 @@ def scolars_import_admission(
# Type admission: traitement particulier # Type admission: traitement particulier
if not cur_adm["type_admission"] and not args.get("type_admission"): if not cur_adm["type_admission"] and not args.get("type_admission"):
args["type_admission"] = 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"]}) adr = sco_etud.adresse_list(cnx, args={"etudid": etud["etudid"]})
if adr: if adr:
args["adresse_id"] = adr[0]["adresse_id"] args["adresse_id"] = adr[0]["adresse_id"]
sco_etud.adresse_edit( sco_etud.adresse_edit( # TODO utiliser modèle
cnx, args, disable_notify=True cnx, args, disable_notify=True
) # pas de notification ici ) # pas de notification ici
else: else:
args["typeadresse"] = "domicile" args["typeadresse"] = "domicile"
args["description"] = "(infos admission)" 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 ) # log('import_adm: %s' % args )
# Change les groupes si nécessaire: # Change les groupes si nécessaire:
if "groupes" in args: if "groupes" in args:

View File

@ -55,6 +55,7 @@ from app.decorators import (
permission_required_compat_scodoc7, permission_required_compat_scodoc7,
) )
from app.models import ( from app.models import (
Adresse,
Admission, Admission,
Departement, Departement,
FormSemestre, 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) members, group, _, sem, _ = sco_groups.get_group_infos(group_id, etat=etat)
formsemestre_id = group["formsemestre_id"] formsemestre_id = group["formsemestre_id"]
cnx = ndb.GetDBConnexion()
H = [ H = [
html_sco_header.html_sem_header( html_sco_header.html_sem_header(
"Étudiants du %s" % (group["group_name"] or "semestre") "É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) infos = sco_portal_apogee.get_infos_apogee(nom, prenom)
if not infos: if not infos:
info_apogee = ( info_apogee = f"""<b>Pas d'information</b>
'<b>Pas d\'information</b> (<a href="etudident_edit_form?etudid=%s">Modifier identité</a>)' (<a class="stdlink" href="{
% etudid url_for("scolar.etudident_edit_form", scodoc_dept=g.scodoc_dept, etudid=etudid)
) }">Modifier identité</a>)"""
nerrs += 1 nerrs += 1
else: else:
if len(infos) == 1: 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 code_nip != nip_apogee:
if fix: if fix:
# Update database # Update database
sco_etud.identite_edit( etud = Identite.get_etud(etudid)
cnx, etud.code_nip = nip_apogee
args={"etudid": etudid, "code_nip": nip_apogee}, db.session.add(etud)
) db.session.commit()
info_apogee = ( info_apogee = (
'<span style="color:green">copié %s</span>' % nip_apogee f'<span style="color:green">copié {nip_apogee}</span>'
) )
nfix += 1 nfix += 1
else: else:
info_apogee = '<span style="color:red">%s</span>' % nip_apogee info_apogee = f'<span style="color:red">{nip_apogee}</span>'
nerrs += 1 nerrs += 1
else: else:
info_apogee = "ok" info_apogee = "ok"
else: else:
info_apogee = ( info_apogee = f"""<b>{len(infos)} correspondances</b>
'<b>%d correspondances</b> (<a href="etudident_edit_form?etudid=%s">Choisir</a>)' (<a class="stdlink" href="{
% (len(infos), etudid) url_for("scolar.etudident_edit_form", scodoc_dept=g.scodoc_dept, etudid=etudid)
) }">Choisir</a>)"""
nerrs += 1 nerrs += 1
# check mail # check mail
if email: if email:
@ -2032,28 +2032,29 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False):
else: else:
if fixmail and len(infos) == 1 and "mail" in infos[0]: if fixmail and len(infos) == 1 and "mail" in infos[0]:
mail_apogee = infos[0]["mail"] mail_apogee = infos[0]["mail"]
adrs = sco_etud.adresse_list(cnx, {"etudid": etudid}) etud = Identite.get_etud(etudid)
if adrs: adresse = etud.adresse
adr = adrs[0] # modif adr existante if adresse:
args = {"adresse_id": adr["adresse_id"], "email": mail_apogee} # modif adr existante
sco_etud.adresse_edit(cnx, args=args, disable_notify=True) adresse.email = mail_apogee
else: else:
# creation adresse # creation adresse
args = {"etudid": etudid, "email": mail_apogee} adresse = Adresse(etudid=etudid, email=mail_apogee)
sco_etud.adresse_create(cnx, args=args) db.session.add(adresse)
db.session.commit()
mailstat = '<span style="color:green">copié</span>' mailstat = '<span style="color:green">copié</span>'
else: else:
mailstat = "inconnu" mailstat = "inconnu"
nmailmissing += 1 nmailmissing += 1
H.append( H.append(
'<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' '<tr><td><a class="stdlink" href="%s">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'
% ( % (
url_for("scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid), url_for("scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid),
nom, nom,
nom_usuel, nom_usuel,
prenom, prenom,
mailstat, mailstat,
code_nip, code_nip or "-",
info_apogee, info_apogee,
) )
) )
@ -2065,42 +2066,30 @@ def check_group_apogee(group_id, etat=None, fix=False, fixmail=False):
H.append("<li>Adresse mail: <b>%d</b> étudiants sans adresse</li>" % nmailmissing) H.append("<li>Adresse mail: <b>%d</b> étudiants sans adresse</li>" % nmailmissing)
H.append("</ul>") H.append("</ul>")
H.append( H.append(
""" f"""
<form method="get" action="%s"> <div class="scobox">
<input type="hidden" name="formsemestre_id" value="%s"/> <form method="get" action="{request.base_url}">
<input type="hidden" name="group_id" value="%s"/> <input type="hidden" name="formsemestre_id" value="{formsemestre_id}"/>
<input type="hidden" name="etat" value="%s"/> <input type="hidden" name="group_id" value="{scu.strnone(group_id)}"/>
<input type="hidden" name="etat" value="{scu.strnone(etat)}"/>
<input type="hidden" name="fix" value="1"/> <input type="hidden" name="fix" value="1"/>
<input type="submit" value="Mettre à jour les codes NIP depuis Apogée"/> <input type="submit" value="Mettre à jour les codes NIP depuis Apogée"/>
</form> </form>
<p><a href="Notes/formsemestre_status?formsemestre_id=%s"> Retour au semestre</a> </div>
"""
% ( <div class="scobox">
request.base_url, <form method="get" action="{request.base_url}">
formsemestre_id, <input type="hidden" name="formsemestre_id" value="{formsemestre_id}"/>
scu.strnone(group_id), <input type="hidden" name="group_id" value="{scu.strnone(group_id)}"/>
scu.strnone(etat), <input type="hidden" name="etat" value="{scu.strnone(etat)}"/>
formsemestre_id,
)
)
H.append(
"""
<form method="get" action="%s">
<input type="hidden" name="formsemestre_id" value="%s"/>
<input type="hidden" name="group_id" value="%s"/>
<input type="hidden" name="etat" value="%s"/>
<input type="hidden" name="fixmail" value="1"/> <input type="hidden" name="fixmail" value="1"/>
<input type="submit" value="Renseigner les e-mail manquants (adresse institutionnelle)"/> <input type="submit" value="Renseigner les e-mail manquants (adresse institutionnelle)"/>
</form> </form>
<p><a href="Notes/formsemestre_status?formsemestre_id=%s"> Retour au semestre</a> </div>
<a class="stdlink" href="{
url_for("notes.formsemestre_status", scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre_id)
}"> Retour au semestre</a>
""" """
% (
request.base_url,
formsemestre_id,
scu.strnone(group_id),
scu.strnone(etat),
formsemestre_id,
)
) )
return "\n".join(H) + html_sco_header.sco_footer() return "\n".join(H) + html_sco_header.sco_footer()