From be3df71ad63914503dbbf14e7253a9f8f359fdb6 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Tue, 26 Apr 2022 15:23:10 +0200 Subject: [PATCH] prise en compte des remarques pour departement.py --- app/api/departements.py | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/app/api/departements.py b/app/api/departements.py index 940bd700..eef35853 100644 --- a/app/api/departements.py +++ b/app/api/departements.py @@ -3,7 +3,7 @@ import app from app import models from app.api import bp -from app.api.auth import token_auth, token_permission_required +from app.api.auth import token_permission_required from app.api.errors import error_response from app.scodoc.sco_permissions import Permission @@ -19,7 +19,7 @@ def departements(): Exemple de résultat : [2, 5, 8, 1, 4, 18] """ # Récupération de tous les départements - depts = models.Departement.query.filter_by(visible=True).all() + depts = models.Departement.query.filter_by(visible=True) # Mise en place de la liste avec tous les ids de départements depts_ids = [d.id for d in depts] @@ -67,14 +67,14 @@ def liste_etudiants(dept: str, formsemestre_id=None): # Si le formsemestre_id a été renseigné if formsemestre_id is not None: # Récupération du formsemestre - formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first() + formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first_or_404() # Récupération du département departement = formsemestre.departement # Si le formsemestre_id n'a pas été renseigné else: # Récupération du formsemestre - departement = models.Departement.query.filter_by(acronym=dept).first() + departement = models.Departement.query.filter_by(acronym=dept).first_or_404() # Récupération des étudiants etudiants = departement.etudiants.all() @@ -129,16 +129,12 @@ def liste_semestres_courant(dept: str): ] """ # Récupération des départements comportant l'acronym mit en paramètre - depts = models.Departement.query.filter_by(acronym=dept).all() - - # Récupération de l'id - id_dept = depts[0].id + dept = models.Departement.query.filter_by(acronym=dept).first_or_404() # Récupération des semestres suivant id_dept - semestres = models.FormSemestre.query.filter_by(dept_id=id_dept, etat=True).all() + semestres = models.FormSemestre.query.filter_by(dept_id=dept.id, etat=True) # Mise en forme des données - data = [d.to_dict() for d in semestres] return jsonify(data) @@ -156,15 +152,13 @@ def referenciel_competences(dept: str, formation_id: int): dept : l'acronym d'un département formation_id : l'id d'une formation """ - depts = models.Departement.query.filter_by(acronym=dept).all() + dept = models.Departement.query.filter_by(acronym=dept).first_or_404() - id_dept = depts[0].id + formation = models.Formation.query.filter_by( + id=formation_id, dept_id=dept.id + ).first_or_404() - formations = models.Formation.query.filter_by( - id=formation_id, dept_id=id_dept - ).all() - - ref_comp = formations[0].referentiel_competence_id + ref_comp = formation.referentiel_competence_id if ref_comp is None: return error_response( @@ -173,10 +167,6 @@ def referenciel_competences(dept: str, formation_id: int): else: return jsonify(ref_comp) - # ref = ApcReferentielCompetences.query.get_or_404(formation_id) - # - # return jsonify(ref.to_dict()) - @bp.route( "/departements//formsemestre//programme", @@ -190,7 +180,7 @@ def semestre_index(dept: str, formsemestre_id: int): app.set_sco_dept(dept) - formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first() + formsemestre = models.FormSemestre.query.filter_by(id=formsemestre_id).first_or_404() ues = formsemestre.query_ues() @@ -218,4 +208,3 @@ def semestre_index(dept: str, formsemestre_id: int): } return data - # return error_response(501, message="not implemented")