prise en compte des remarques sur etudiants.py

This commit is contained in:
leonard_montalbano 2022-04-26 14:48:43 +02:00
parent 06844380ad
commit 4c28d140a6

View File

@ -8,51 +8,12 @@ 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_etu_from_request from app.api.tools import get_etu_from_request
from app.scodoc.sco_bulletins_json import make_json_formsemestre_bulletinetud from app.models import FormSemestreInscription, FormSemestre, Identite
from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json
from app.scodoc.sco_groups import get_etud_groups from app.scodoc.sco_groups import get_etud_groups
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
@bp.route("/etudiants", methods=["GET"])
@token_permission_required(Permission.APIView)
def etudiants():
"""
Retourne la liste de tous les étudiants
Exemple de résultat :
{
"civilite": "X",
"code_ine": null,
"code_nip": null,
"date_naissance": null,
"email": null,
"emailperso": null,
"etudid": 18,
"nom": "MOREL",
"prenom": "JACQUES"
},
{
"civilite": "X",
"code_ine": null,
"code_nip": null,
"date_naissance": null,
"email": null,
"emailperso": null,
"etudid": 19,
"nom": "FOURNIER",
"prenom": "ANNE"
},
...
"""
# Récupération de tous les étudiants
etu = models.Identite.query.all()
# Mise en forme des données
data = [d.to_dict_bul(include_urls=False) for d in etu]
return jsonify(data)
@bp.route("/etudiants/courant", methods=["GET"]) @bp.route("/etudiants/courant", methods=["GET"])
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etudiants_courant(): def etudiants_courant():
@ -85,13 +46,13 @@ def etudiants_courant():
... ...
""" """
# Récupération de tous les étudiants # Récupération de tous les étudiants
etus = models.Identite.query.all() etus = Identite.query.filter(
Identite.id == FormSemestreInscription.etudid,
FormSemestreInscription.formsemestre_id == FormSemestre.id,
FormSemestre.date_debut <= app.db.func.now(),
FormSemestre.date_fin >= app.db.func.now())
data = [] data = [etu.to_dict_bul(include_urls=False) for etu in etus]
# Récupère uniquement les étudiants courant
for etu in etus:
if etu.inscription_courante() is not None:
data.append(etu.to_dict_bul(include_urls=False))
return jsonify(data) return jsonify(data)
@ -190,7 +151,7 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None)
for formsemestre_inscription in formsemestres_inscriptions: for formsemestre_inscription in formsemestres_inscriptions:
res = models.FormSemestre.query.filter_by( res = models.FormSemestre.query.filter_by(
id=formsemestre_inscription.formsemestre_id id=formsemestre_inscription.formsemestre_id
).first() ).first_or_404()
formsemestres.append(res) formsemestres.append(res)
data = [] data = []
@ -227,17 +188,15 @@ def etudiant_bulletin_semestre(
""" """
# Fonction utilisée : app.scodoc.sco_bulletins_json.make_json_formsemestre_bulletinetud() # Fonction utilisée : app.scodoc.sco_bulletins_json.make_json_formsemestre_bulletinetud()
formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first() formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first_or_404()
dept = models.Departement.query.filter_by(id=formsemestre.dept_id).first() dept = models.Departement.query.filter_by(id=formsemestre.dept_id).first_or_404()
app.set_sco_dept(dept.acronym) app.set_sco_dept(dept.acronym)
if etudid is None:
# Récupération de l'étudiant # Récupération de l'étudiant
try: try:
etu = get_etu_from_request(etudid, nip, ine) etu = get_etu_from_request(etudid, nip, ine)
etudid = etu.etudid
except AttributeError: except AttributeError:
return error_response( return error_response(
409, 409,
@ -245,7 +204,7 @@ def etudiant_bulletin_semestre(
"Veilliez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide", "Veilliez vérifier que l'id de l'étudiant (etudid, nip, ine) est valide",
) )
return make_json_formsemestre_bulletinetud(formsemestre_id, etudid) return get_formsemestre_bulletin_etud_json(formsemestre, etu)
@bp.route( @bp.route(
@ -311,7 +270,7 @@ def etudiant_groups(
) )
# Récupération du formsemestre # Récupération du formsemestre
sem = models.FormSemestre.query.filter_by(id=formsemestre_id).first() sem = models.FormSemestre.query.filter_by(id=formsemestre_id).first_or_404()
try: try:
# Utilisation de la fonction get_etud_groups # Utilisation de la fonction get_etud_groups
data = get_etud_groups(etudid, sem.id) data = get_etud_groups(etudid, sem.id)