factorisation des fichiers departements.py etudiant.py et formsemestre.py
This commit is contained in:
parent
07123089e2
commit
79b79ddc76
@ -71,16 +71,12 @@ def liste_etudiants(dept: str, formsemestre_id=None):
|
||||
formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first()
|
||||
# Récupération du département
|
||||
departement = formsemestre.departement
|
||||
# Récupération des étudiants
|
||||
etudiants = departement.etudiants.all()
|
||||
|
||||
# Mise en forme des données
|
||||
list_etu = [etu.to_dict_bul(include_urls=False) for etu in etudiants]
|
||||
|
||||
# Si le formsemestre_id n'a pas été renseigné
|
||||
else:
|
||||
# Récupération du formsemestre
|
||||
departement = models.Departement.query.filter_by(acronym=dept).first()
|
||||
|
||||
# Récupération des étudiants
|
||||
etudiants = departement.etudiants.all()
|
||||
|
||||
@ -203,6 +199,9 @@ def semestre_index(dept: str, formsemestre_id: int):
|
||||
ues = formsemestre.query_ues()
|
||||
|
||||
ues_dict = []
|
||||
ressources = []
|
||||
saes = []
|
||||
|
||||
for ue in ues:
|
||||
ues_dict.append(ue.to_dict())
|
||||
ressources = ue.get_ressources()
|
||||
|
@ -7,6 +7,7 @@ from app import models
|
||||
from app.api import bp
|
||||
from app.api.errors import error_response
|
||||
from app.api.auth import token_auth, token_permission_required
|
||||
from app.api.tools import get_etu_from_request
|
||||
from app.scodoc.sco_bulletins_json import make_json_formsemestre_bulletinetud
|
||||
from app.scodoc.sco_groups import get_etud_groups
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
@ -52,7 +53,6 @@ def etudiants():
|
||||
data = [d.to_dict_bul(include_urls=False) for d in etu]
|
||||
|
||||
return jsonify(data)
|
||||
# return error_response(501, message="Not implemented")
|
||||
|
||||
|
||||
@bp.route("/etudiants/courant", methods=["GET"])
|
||||
@ -97,7 +97,6 @@ def etudiants_courant():
|
||||
data.append(etu.to_dict_bul(include_urls=False))
|
||||
|
||||
return jsonify(data)
|
||||
# return error_response(501, message="Not implemented")
|
||||
|
||||
|
||||
@bp.route("/etudiant/etudid/<int:etudid>", methods=["GET"])
|
||||
@ -126,32 +125,8 @@ def etudiant(etudid: int = None, nip: int = None, ine: int = None):
|
||||
"prenom": "JACQUES"
|
||||
}
|
||||
"""
|
||||
# etu = []
|
||||
|
||||
if etudid is None:
|
||||
if nip is None: # si ine
|
||||
etu = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
else: # si nip
|
||||
etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
|
||||
else: # si etudid
|
||||
etu = models.Identite.query.filter_by(id=etudid).first()
|
||||
|
||||
|
||||
|
||||
# if etudid is not None: # Si route etudid
|
||||
# # Récupération de l'étudiant
|
||||
# etu = models.Identite.query.filter_by(id=etudid).first()
|
||||
#
|
||||
# if nip is not None: # Si route nip
|
||||
# # Récupération de l'étudiant
|
||||
# etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
#
|
||||
# breakpoint()
|
||||
#
|
||||
# if ine is not None: # Si route ine
|
||||
# # Récupération de l'étudiant
|
||||
# etu = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
# Récupération de l'étudiant
|
||||
etu = get_etu_from_request(etudid, nip, ine)
|
||||
|
||||
# Mise en forme des données
|
||||
data = etu.to_dict_bul(include_urls=False)
|
||||
@ -210,31 +185,19 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
|
||||
# Récupération de toutes les inscriptions
|
||||
inscriptions = models.FormSemestreInscription.query.all()
|
||||
|
||||
# Récupération de l'étudiant
|
||||
etu = get_etu_from_request(etudid, nip, ine)
|
||||
|
||||
sems = []
|
||||
# Filtre les inscriptions contenant l'étudiant
|
||||
for sem in inscriptions:
|
||||
if etudid is None:
|
||||
if nip is None: # si ine
|
||||
# Récupération de l'étudiant
|
||||
etu = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
if sem.etudid == etu.etudid:
|
||||
sems.append(sem)
|
||||
else: # si nip
|
||||
# Récupération de l'étudiant
|
||||
etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
if sem.etudid == etu.etudid:
|
||||
sems.append(sem)
|
||||
else: # si etudid
|
||||
if sem.etudid == etudid:
|
||||
sems.append(sem)
|
||||
|
||||
# Mise en forme des données
|
||||
# data_inscriptions = [d.to_dict() for d in sems]
|
||||
|
||||
formsemestres = []
|
||||
|
||||
# Filtre les formsemestre contenant les inscriptions de l'étudiant
|
||||
for sem in sems:#data_inscriptions:
|
||||
for sem in sems: #data_inscriptions:
|
||||
res = models.FormSemestre.query.filter_by(id=sem.formsemestre_id).first()
|
||||
formsemestres.append(res)
|
||||
|
||||
@ -269,12 +232,9 @@ def etudiant_bulletin_semestre(formsemestre_id, etudid: int = None, nip: int = N
|
||||
app.set_sco_dept(dept.acronym)
|
||||
|
||||
if etudid is None:
|
||||
if nip is None: # si ine
|
||||
etu = models.Identite.query.filter_by(code_nip=str(ine)).first()
|
||||
return make_json_formsemestre_bulletinetud(formsemestre_id, etu.etudid)
|
||||
else: # si nip
|
||||
etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
return make_json_formsemestre_bulletinetud(formsemestre_id, etu.etudid)
|
||||
# Récupération de l'étudiant
|
||||
etu = get_etu_from_request(etudid, nip, ine)
|
||||
etudid = etu.etudid
|
||||
|
||||
return make_json_formsemestre_bulletinetud(formsemestre_id, etudid)
|
||||
|
||||
@ -322,16 +282,8 @@ def etudiant_groups(formsemestre_id: int, etudid: int = None, nip: int = None, i
|
||||
# Fonction utilisée : app.scodoc.sco_groups.get_etud_groups()
|
||||
|
||||
if etudid is None:
|
||||
if nip is not None: # Si route nip
|
||||
# Récupération de l'étudiant
|
||||
etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
# Récupération de sont etudid
|
||||
etudid = etu.etudid
|
||||
|
||||
if ine is not None: # Si route ine
|
||||
# Récupération de l'étudiant
|
||||
etu = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
# Récupération de sont etudid
|
||||
etu = get_etu_from_request(etudid, nip, ine)
|
||||
etudid = etu.etudid
|
||||
|
||||
# Récupération du formsemestre
|
||||
|
@ -6,7 +6,7 @@ from app import models
|
||||
from app.api import bp
|
||||
from app.api.errors import error_response
|
||||
from app.api.auth import token_auth, token_permission_required
|
||||
from app.scodoc.sco_bulletins import formsemestre_bulletinetud_dict
|
||||
from app.api.tools import get_etu_from_request
|
||||
from app.scodoc.sco_bulletins_json import make_json_formsemestre_bulletinetud
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
from app.scodoc.sco_pvjury import formsemestre_pvjury
|
||||
@ -24,10 +24,10 @@ def formsemestre(formsemestre_id: int):
|
||||
|
||||
"""
|
||||
# Récupération de tous les formsemestres
|
||||
list_formsemetre = models.FormSemestre.query.filter_by(id=formsemestre_id)
|
||||
formsemetre = models.FormSemestre.query.filter_by(id=formsemestre_id).first()
|
||||
|
||||
# Mise en forme des données
|
||||
data = list_formsemetre[0].to_dict()
|
||||
data = formsemetre.to_dict()
|
||||
|
||||
return jsonify(data)
|
||||
|
||||
@ -61,28 +61,16 @@ def etudiant_bulletin(formsemestre_id, dept, format="json", etudid: int = None,
|
||||
|
||||
app.set_sco_dept(dept)
|
||||
|
||||
data = []
|
||||
|
||||
if etudid is None:
|
||||
if nip is None: # si ine
|
||||
etu = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
# data = formsemestre_bulletinetud_dict(formsemestre_id, etu.id)
|
||||
data = make_json_formsemestre_bulletinetud(formsemestre_id, etu.id)
|
||||
return data
|
||||
else: # si nip
|
||||
etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
# data = formsemestre_bulletinetud_dict(formsemestre_id, etu.id)
|
||||
data = make_json_formsemestre_bulletinetud(formsemestre_id, etu.id)
|
||||
return data
|
||||
else: # si etudid
|
||||
# data = formsemestre_bulletinetud_dict(formsemestre_id, etudid)
|
||||
# Récupération de l'étudiant
|
||||
etu = get_etu_from_request(etudid, nip, ine)
|
||||
etudid = etu.etudid
|
||||
|
||||
data = make_json_formsemestre_bulletinetud(formsemestre_id, etudid)
|
||||
# return jsonify(data)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
|
||||
|
||||
# if args[0] == "short":
|
||||
# data = formsemestre_bulletinetud_dict(formsemestre_id, etudid, version=args[0])
|
||||
# elif args[0] == "selectevals":
|
||||
|
22
app/api/tools.py
Normal file
22
app/api/tools.py
Normal file
@ -0,0 +1,22 @@
|
||||
from app import models
|
||||
|
||||
def get_etu_from_request(etudid, nip, ine):
|
||||
"""
|
||||
Fonction qui retourne un etudiant en fonction de l'etudid, code nip et code ine rentré en paramètres
|
||||
|
||||
etudid : None ou un int etudid
|
||||
nip : None ou un int code_nip
|
||||
ine : None ou un int code_ine
|
||||
|
||||
Exemple de résultat: <Itendite>
|
||||
"""
|
||||
|
||||
if etudid is None:
|
||||
if nip is None: # si ine
|
||||
etu = models.Identite.query.filter_by(code_ine=str(ine)).first()
|
||||
else: # si nip
|
||||
etu = models.Identite.query.filter_by(code_nip=str(nip)).first()
|
||||
else: # si etudid
|
||||
etu = models.Identite.query.filter_by(id=etudid).first()
|
||||
|
||||
return etu
|
Loading…
Reference in New Issue
Block a user