Fix: synchro etud, unicité codes
This commit is contained in:
parent
20bb9cc9ed
commit
a904db9eee
@ -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(
|
||||
|
@ -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:
|
||||
|
@ -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 = (
|
||||
'<b>Pas d\'information</b> (<a href="etudident_edit_form?etudid=%s">Modifier identité</a>)'
|
||||
% etudid
|
||||
)
|
||||
info_apogee = f"""<b>Pas d'information</b>
|
||||
(<a class="stdlink" href="{
|
||||
url_for("scolar.etudident_edit_form", scodoc_dept=g.scodoc_dept, etudid=etudid)
|
||||
}">Modifier identité</a>)"""
|
||||
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 = (
|
||||
'<span style="color:green">copié %s</span>' % nip_apogee
|
||||
f'<span style="color:green">copié {nip_apogee}</span>'
|
||||
)
|
||||
nfix += 1
|
||||
else:
|
||||
info_apogee = '<span style="color:red">%s</span>' % nip_apogee
|
||||
info_apogee = f'<span style="color:red">{nip_apogee}</span>'
|
||||
nerrs += 1
|
||||
else:
|
||||
info_apogee = "ok"
|
||||
else:
|
||||
info_apogee = (
|
||||
'<b>%d correspondances</b> (<a href="etudident_edit_form?etudid=%s">Choisir</a>)'
|
||||
% (len(infos), etudid)
|
||||
)
|
||||
info_apogee = f"""<b>{len(infos)} correspondances</b>
|
||||
(<a class="stdlink" href="{
|
||||
url_for("scolar.etudident_edit_form", scodoc_dept=g.scodoc_dept, etudid=etudid)
|
||||
}">Choisir</a>)"""
|
||||
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 = '<span style="color:green">copié</span>'
|
||||
else:
|
||||
mailstat = "inconnu"
|
||||
nmailmissing += 1
|
||||
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),
|
||||
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("<li>Adresse mail: <b>%d</b> étudiants sans adresse</li>" % nmailmissing)
|
||||
H.append("</ul>")
|
||||
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"/>
|
||||
f"""
|
||||
<div class="scobox">
|
||||
<form method="get" action="{request.base_url}">
|
||||
<input type="hidden" name="formsemestre_id" value="{formsemestre_id}"/>
|
||||
<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="submit" value="Mettre à jour les codes NIP depuis Apogée"/>
|
||||
</form>
|
||||
<p><a href="Notes/formsemestre_status?formsemestre_id=%s"> Retour au semestre</a>
|
||||
"""
|
||||
% (
|
||||
request.base_url,
|
||||
formsemestre_id,
|
||||
scu.strnone(group_id),
|
||||
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"/>
|
||||
</div>
|
||||
|
||||
<div class="scobox">
|
||||
<form method="get" action="{request.base_url}">
|
||||
<input type="hidden" name="formsemestre_id" value="{formsemestre_id}"/>
|
||||
<input type="hidden" name="group_id" value="{scu.strnone(group_id)}"/>
|
||||
<input type="hidden" name="etat" value="{scu.strnone(etat)}"/>
|
||||
<input type="hidden" name="fixmail" value="1"/>
|
||||
<input type="submit" value="Renseigner les e-mail manquants (adresse institutionnelle)"/>
|
||||
</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()
|
||||
|
Loading…
Reference in New Issue
Block a user