2022-03-02 16:45:47 +01:00
|
|
|
############################################### Departements ##########################################################
|
2022-05-03 13:35:17 +02:00
|
|
|
|
|
|
|
from flask import jsonify
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
import app
|
2022-03-02 16:45:47 +01:00
|
|
|
from app import models
|
|
|
|
from app.api import bp
|
2022-05-03 13:35:17 +02:00
|
|
|
from app.api.auth import token_auth, token_permission_required
|
2022-05-05 18:11:44 +02:00
|
|
|
from app.models import FormSemestre
|
2022-03-04 17:16:08 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
@bp.route("/departements_ids", methods=["GET"])
|
2022-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
2022-04-13 12:39:10 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-05-05 18:11:44 +02:00
|
|
|
def departements_ids():
|
|
|
|
"""Liste des ids de départements"""
|
|
|
|
return jsonify([dept.id for dept in models.Departement.query])
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/departement/<int:dept_id>", methods=["GET"])
|
|
|
|
@token_auth.login_required
|
|
|
|
@token_permission_required(Permission.APIView)
|
|
|
|
def departement(dept_id: int):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-05-05 18:11:44 +02:00
|
|
|
Info sur un département.
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-04-28 09:06:20 +02:00
|
|
|
Exemple de résultat :
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"acronym": "TAPI",
|
|
|
|
"description": null,
|
|
|
|
"visible": true,
|
|
|
|
"date_creation": "Fri, 15 Apr 2022 12:19:28 GMT"
|
2022-05-05 18:11:44 +02:00
|
|
|
}
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-05-05 18:11:44 +02:00
|
|
|
dept = models.Departement.query.filter_by(dept_id=dept_id).first_or_404()
|
|
|
|
return jsonify(dept.to_dict())
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
@bp.route("/departements", methods=["GET"])
|
|
|
|
@token_auth.login_required
|
|
|
|
@token_permission_required(Permission.APIView)
|
|
|
|
def departements():
|
|
|
|
"""Liste les départements"""
|
|
|
|
return jsonify([dept.to_dict() for dept in models.Departement.query])
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
@bp.route("/departement/<string:dept_ident>/etudiants", methods=["GET"])
|
|
|
|
# @bp.route(
|
|
|
|
# "/departement/<string:dept_ident>/etudiants/list/<int:formsemestre_id>", methods=["GET"]
|
|
|
|
# )
|
2022-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-05-05 18:11:44 +02:00
|
|
|
def list_etudiants(dept_ident: str):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
Retourne la liste des étudiants d'un département
|
|
|
|
|
|
|
|
dept: l'acronym d'un département
|
|
|
|
formsemestre_id: l'id d'un formesemestre
|
|
|
|
|
|
|
|
Exemple de résultat :
|
2022-04-27 15:29:09 +02:00
|
|
|
[
|
|
|
|
{
|
2022-05-05 18:11:44 +02:00
|
|
|
"civilite": "M",
|
|
|
|
"ine": "7899X61616",
|
|
|
|
"nip": "F6777H88",
|
2022-03-02 16:45:47 +01:00
|
|
|
"date_naissance": null,
|
2022-05-05 18:11:44 +02:00
|
|
|
"email": "toto@toto.fr",
|
2022-03-02 16:45:47 +01:00
|
|
|
"emailperso": null,
|
|
|
|
"etudid": 18,
|
|
|
|
"nom": "MOREL",
|
|
|
|
"prenom": "JACQUES"
|
2022-04-27 15:29:09 +02:00
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-05-05 18:11:44 +02:00
|
|
|
# Le département, spécifié par un id ou un acronyme
|
|
|
|
try:
|
|
|
|
dept_id = int(dept_ident)
|
|
|
|
except ValueError:
|
|
|
|
dept_id = None
|
|
|
|
if dept_id is None:
|
|
|
|
departement = models.Departement.query.filter_by(
|
|
|
|
acronym=dept_ident
|
2022-04-26 17:12:30 +02:00
|
|
|
).first_or_404()
|
2022-03-03 16:25:29 +01:00
|
|
|
else:
|
2022-05-05 18:11:44 +02:00
|
|
|
departement = models.Departement.query.get_or_404(dept_id)
|
2022-03-03 16:25:29 +01:00
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
return jsonify([etud.to_dict_short() for etud in departement.etudiants])
|
2022-03-03 16:25:29 +01:00
|
|
|
|
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
@bp.route("/departement/<string:dept_ident>/formsemestres_courants", methods=["GET"])
|
2022-05-03 13:35:17 +02:00
|
|
|
@token_auth.login_required
|
2022-04-14 14:56:36 +02:00
|
|
|
@token_permission_required(Permission.APIView)
|
2022-05-05 18:11:44 +02:00
|
|
|
def liste_semestres_courant(dept_ident: str):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
|
|
|
Liste des semestres actifs d'un départements donné
|
|
|
|
|
|
|
|
dept: l'acronym d'un département
|
|
|
|
|
|
|
|
Exemple de résultat :
|
2022-04-27 15:29:09 +02:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"titre": "master machine info",
|
|
|
|
"gestion_semestrielle": false,
|
|
|
|
"scodoc7_id": null,
|
|
|
|
"date_debut": "01/09/2021",
|
|
|
|
"bul_bgcolor": null,
|
|
|
|
"date_fin": "15/12/2022",
|
|
|
|
"resp_can_edit": false,
|
|
|
|
"dept_id": 1,
|
|
|
|
"etat": true,
|
|
|
|
"resp_can_change_ens": false,
|
|
|
|
"id": 1,
|
|
|
|
"modalite": "FI",
|
|
|
|
"ens_can_edit_eval": false,
|
|
|
|
"formation_id": 1,
|
|
|
|
"gestion_compensation": false,
|
|
|
|
"elt_sem_apo": null,
|
|
|
|
"semestre_id": 1,
|
|
|
|
"bul_hide_xml": false,
|
|
|
|
"elt_annee_apo": null,
|
|
|
|
"block_moyennes": false,
|
|
|
|
"formsemestre_id": 1,
|
|
|
|
"titre_num": "master machine info semestre 1",
|
|
|
|
"date_debut_iso": "2021-09-01",
|
|
|
|
"date_fin_iso": "2022-12-15",
|
|
|
|
"responsables": [
|
|
|
|
3,
|
|
|
|
2
|
|
|
|
]
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-05-05 18:11:44 +02:00
|
|
|
# Le département, spécifié par un id ou un acronyme
|
|
|
|
try:
|
|
|
|
dept_id = int(dept_ident)
|
|
|
|
except ValueError:
|
|
|
|
dept_id = None
|
|
|
|
if dept_id is None:
|
|
|
|
departement = models.Departement.query.filter_by(
|
|
|
|
acronym=dept_ident
|
|
|
|
).first_or_404()
|
|
|
|
else:
|
|
|
|
departement = models.Departement.query.get_or_404(dept_id)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
# Les semestres en cours de ce département
|
|
|
|
formsemestres = models.FormSemestre.query.filter(
|
|
|
|
dept_id == departement.id,
|
|
|
|
FormSemestre.date_debut <= app.db.func.now(),
|
|
|
|
FormSemestre.date_fin >= app.db.func.now(),
|
|
|
|
)
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-05-05 18:11:44 +02:00
|
|
|
return jsonify([d.to_dict() for d in formsemestres])
|