2022-04-22 16:22:10 +02:00
|
|
|
from app import models
|
|
|
|
|
2022-05-16 15:45:11 +02:00
|
|
|
from app.api.errors import error_response
|
|
|
|
from app.models import Identite
|
|
|
|
|
|
|
|
|
|
|
|
def get_last_instance_etud_from_etudid_or_nip_or_ine(
|
2022-05-09 16:26:23 +02:00
|
|
|
etudid=None, nip=None, ine=None
|
|
|
|
) -> models.Identite:
|
2022-04-22 16:22:10 +02:00
|
|
|
"""
|
2022-05-16 15:45:11 +02:00
|
|
|
Retourne l'instance de l'etudiant la plus récente en fonction de l'etudid, code nip et code ine rentré en paramètres
|
2022-04-22 16:22:10 +02:00
|
|
|
|
|
|
|
etudid : None ou un int etudid
|
|
|
|
nip : None ou un int code_nip
|
|
|
|
ine : None ou un int code_ine
|
|
|
|
|
2022-05-09 16:26:23 +02:00
|
|
|
Return None si étudiant inexistant.
|
2022-04-22 16:22:10 +02:00
|
|
|
"""
|
2022-05-16 15:45:11 +02:00
|
|
|
if etudid is not None:
|
|
|
|
etud = Identite.query.get(etudid)
|
|
|
|
else:
|
|
|
|
if nip is not None:
|
|
|
|
query = Identite.query.filter_by(code_nip=nip)
|
|
|
|
elif ine is not None:
|
|
|
|
query = Identite.query.filter_by(code_ine=ine)
|
|
|
|
else:
|
|
|
|
return error_response(
|
|
|
|
404,
|
|
|
|
message="parametre manquant",
|
|
|
|
)
|
|
|
|
if query.count() > 1: # cas rare d'un étudiant présent dans plusieurs depts
|
|
|
|
etuds = []
|
|
|
|
for e in query:
|
|
|
|
admission = e.admission.first()
|
|
|
|
etuds.append((((admission.annee or 0) if admission else 0), e))
|
|
|
|
etuds.sort()
|
|
|
|
etud = etuds[-1][1]
|
|
|
|
else:
|
|
|
|
etud = query.first()
|
2022-04-22 16:22:10 +02:00
|
|
|
|
2022-04-26 13:46:09 +02:00
|
|
|
return etud
|