forked from ScoDoc/ScoDoc
mise à jour de la fonction renvoyant un étudiant suivant son etudid, nip ou ine pour renvoyer la dernière instance de celui si
This commit is contained in:
parent
8c481bd0d1
commit
ffcc0897f2
@ -14,6 +14,7 @@ import app
|
|||||||
from app.api import bp
|
from app.api import bp
|
||||||
from app.api.errors import error_response
|
from app.api.errors import error_response
|
||||||
from app.api.auth import token_auth, token_permission_required
|
from app.api.auth import token_auth, token_permission_required
|
||||||
|
from app.api.tools import get_last_instance_etud_from_etudid_or_nip_or_ine
|
||||||
from app.models import Departement, FormSemestreInscription, FormSemestre, Identite
|
from app.models import Departement, FormSemestreInscription, FormSemestre, Identite
|
||||||
from app.scodoc import sco_bulletins
|
from app.scodoc import sco_bulletins
|
||||||
from app.scodoc import sco_groups
|
from app.scodoc import sco_groups
|
||||||
@ -104,27 +105,7 @@ def etudiant(etudid: int = None, nip: str = None, ine: str = None):
|
|||||||
"description": ""
|
"description": ""
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
if etudid is not None:
|
etud = get_last_instance_etud_from_etudid_or_nip_or_ine(etudid, nip, ine)
|
||||||
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()
|
|
||||||
|
|
||||||
if etud is None:
|
if etud is None:
|
||||||
return error_response(
|
return error_response(
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
from app import models
|
from app import models
|
||||||
|
|
||||||
### TODO Faire en sorte de renvoyer l'étudiant qui a son inscription la plus récente
|
from app.api.errors import error_response
|
||||||
def get_etud_from_etudid_or_nip_or_ine(
|
from app.models import Identite
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_instance_etud_from_etudid_or_nip_or_ine(
|
||||||
etudid=None, nip=None, ine=None
|
etudid=None, nip=None, ine=None
|
||||||
) -> models.Identite:
|
) -> models.Identite:
|
||||||
"""
|
"""
|
||||||
etudiant en fonction de l'etudid, code nip et code ine rentré en paramètres
|
Retourne l'instance de l'etudiant la plus récente en fonction de l'etudid, code nip et code ine rentré en paramètres
|
||||||
|
|
||||||
etudid : None ou un int etudid
|
etudid : None ou un int etudid
|
||||||
nip : None ou un int code_nip
|
nip : None ou un int code_nip
|
||||||
@ -13,12 +16,27 @@ def get_etud_from_etudid_or_nip_or_ine(
|
|||||||
|
|
||||||
Return None si étudiant inexistant.
|
Return None si étudiant inexistant.
|
||||||
"""
|
"""
|
||||||
if etudid is None:
|
if etudid is not None:
|
||||||
if nip is None: # si ine
|
etud = Identite.query.get(etudid)
|
||||||
etud = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
else:
|
||||||
else: # si nip
|
if nip is not None:
|
||||||
etud = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
query = Identite.query.filter_by(code_nip=nip)
|
||||||
else: # si etudid
|
elif ine is not None:
|
||||||
etud = models.Identite.query.filter_by(id=etudid).first()
|
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()
|
||||||
|
|
||||||
return etud
|
return etud
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user