forked from ScoDoc/ScoDoc
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
##############################################################################
|
|
# ScoDoc
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
# See LICENSE
|
|
##############################################################################
|
|
"""ScoDoc 9 API : outils
|
|
"""
|
|
|
|
from sqlalchemy import desc
|
|
|
|
from app import models
|
|
from app.api.errors import error_response
|
|
from app.models import Identite, Admission
|
|
|
|
|
|
def get_etud(etudid=None, nip=None, ine=None) -> models.Identite:
|
|
"""
|
|
L'instance d'étudiant la plus récente en fonction de l'etudid,
|
|
ou du code nip ou code ine.
|
|
|
|
etudid : None ou un int etudid
|
|
nip : None ou un int code_nip
|
|
ine : None ou un int code_ine
|
|
|
|
Return None si étudiant inexistant.
|
|
"""
|
|
if etudid is not None:
|
|
return Identite.query.get(etudid)
|
|
|
|
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",
|
|
)
|
|
return query.join(Admission).order_by(desc(Admission.annee)).first()
|