forked from ScoDoc/ScoDoc
API: /formsemestres/query
This commit is contained in:
parent
312d0c1917
commit
847e275b26
@ -7,8 +7,7 @@
|
||||
"""
|
||||
ScoDoc 9 API : accès aux formsemestres
|
||||
"""
|
||||
|
||||
from flask import jsonify
|
||||
from flask import abort, jsonify, request
|
||||
|
||||
import app
|
||||
from app import models
|
||||
@ -69,25 +68,48 @@ def formsemestre_infos(formsemestre_id: int):
|
||||
return jsonify(formsemestre.to_dict_api())
|
||||
|
||||
|
||||
@bp.route("/formsemestre/apo/<string:etape_apo>", methods=["GET"])
|
||||
@bp.route("/formsemestres/query", methods=["GET"])
|
||||
@token_auth.login_required
|
||||
@token_permission_required(Permission.APIView)
|
||||
def formsemestre_apo(etape_apo: str):
|
||||
def formsemestres_query():
|
||||
"""
|
||||
Retourne les informations sur les formsemestres ayant cette étape Apogée
|
||||
Retourne les formsemestres filtrés par
|
||||
étape Apogée ou année scolaire ou département (acronyme ou id)
|
||||
|
||||
etape_apo : un code étape apogée
|
||||
|
||||
Exemple de résultat :
|
||||
[
|
||||
{ ...formsemestre...
|
||||
}, ...
|
||||
]
|
||||
annee_scolaire : année de début de l'année scolaire
|
||||
dept_acronym : acronyme du département (eg "RT")
|
||||
dept_id : id du département
|
||||
"""
|
||||
formsemestres = FormSemestre.query.filter(
|
||||
FormSemestreEtape.etape_apo == etape_apo,
|
||||
FormSemestreEtape.formsemestre_id == FormSemestre.id,
|
||||
)
|
||||
etape_apo = request.args.get("etape_apo")
|
||||
annee_scolaire = request.args.get("annee_scolaire")
|
||||
dept_acronym = request.args.get("dept_acronym")
|
||||
dept_id = request.args.get("dept_id")
|
||||
formsemestres = FormSemestre.query
|
||||
if etape_apo is not None:
|
||||
formsemestres = formsemestres.join(FormSemestreEtape).filter(
|
||||
FormSemestreEtape.etape_apo == etape_apo
|
||||
)
|
||||
if annee_scolaire is not None:
|
||||
try:
|
||||
annee_scolaire_int = int(annee_scolaire)
|
||||
except ValueError:
|
||||
abort(404, "invalid annee_scolaire: not int")
|
||||
debut_annee = scu.date_debut_anne_scolaire(annee_scolaire_int)
|
||||
fin_annee = scu.date_fin_anne_scolaire(annee_scolaire_int)
|
||||
formsemestres = formsemestres.filter(
|
||||
FormSemestre.date_fin >= debut_annee, FormSemestre.date_debut <= fin_annee
|
||||
)
|
||||
if dept_acronym is not None:
|
||||
formsemestres = formsemestres.join(models.Departement).filter_by(
|
||||
acronym=dept_acronym
|
||||
)
|
||||
if dept_id is not None:
|
||||
try:
|
||||
dept_id = int(dept_id)
|
||||
except ValueError:
|
||||
abort(404, "invalid dept_id: not int")
|
||||
formsemestres = formsemestres.filter_by(dept_id=dept_id)
|
||||
|
||||
return jsonify([formsemestre.to_dict_api() for formsemestre in formsemestres])
|
||||
|
||||
|
@ -1893,6 +1893,8 @@ class BasePreferences(object):
|
||||
# log(f"loading preferences for dept_id={self.dept_id}")
|
||||
|
||||
cnx = ndb.GetDBConnexion()
|
||||
if self.dept_id:
|
||||
g.scodoc_dept_id = self.dept_id
|
||||
preflist = self._editor.list(cnx, {"dept_id": self.dept_id})
|
||||
self.prefs = {None: {}} # { formsemestre_id (or None) : { name : value } }
|
||||
self.default = {} # { name : default_value }
|
||||
|
@ -173,8 +173,9 @@ POST_JSON(
|
||||
|
||||
POST_JSON(f"/partition/{2379}/delete")
|
||||
|
||||
# # --- Recupere la liste de tous les semestres:
|
||||
# sems = GET(s, "Notes/formsemestre_list?format=json", "Aucun semestre !")
|
||||
# Recherche de formsemestres
|
||||
sems = GET(f"/formsemestres/query?etape_apo=V1RT&annee_scolaire=2021")
|
||||
|
||||
|
||||
# # sems est une liste de semestres (dictionnaires)
|
||||
# for sem in sems:
|
||||
|
Loading…
Reference in New Issue
Block a user