2022-07-19 22:17:10 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2022-07-19 22:17:10 +02:00
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
ScoDoc 9 API : accès aux formations
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
CATEGORY
|
|
|
|
--------
|
|
|
|
Formations
|
2022-07-19 22:17:10 +02:00
|
|
|
"""
|
|
|
|
|
2023-04-10 11:25:46 +02:00
|
|
|
from flask import flash, g, request
|
2023-04-06 16:10:32 +02:00
|
|
|
from flask_json import as_json
|
2022-07-27 16:03:14 +02:00
|
|
|
from flask_login import login_required
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-05-03 13:35:17 +02:00
|
|
|
import app
|
2023-04-10 11:25:46 +02:00
|
|
|
from app import db, log
|
2022-07-27 16:03:14 +02:00
|
|
|
from app.api import api_bp as bp, api_web_bp
|
2024-07-17 12:03:08 +02:00
|
|
|
from app.api import api_permission_required as permission_required
|
|
|
|
from app.decorators import scodoc
|
2024-06-21 00:53:52 +02:00
|
|
|
from app.models import APO_CODE_STR_LEN
|
2022-08-07 19:56:25 +02:00
|
|
|
from app.scodoc.sco_utils import json_error
|
2023-04-10 11:25:46 +02:00
|
|
|
from app.models import (
|
|
|
|
ApcNiveau,
|
|
|
|
ApcParcours,
|
|
|
|
Formation,
|
2024-06-21 00:53:52 +02:00
|
|
|
Module,
|
2023-04-10 11:25:46 +02:00
|
|
|
UniteEns,
|
|
|
|
)
|
2022-05-03 13:35:17 +02:00
|
|
|
from app.scodoc import sco_formations
|
2022-03-04 17:16:08 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
@bp.route("/formations")
|
|
|
|
@api_web_bp.route("/formations")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2022-06-17 15:46:17 +02:00
|
|
|
def formations():
|
|
|
|
"""
|
2024-07-24 17:34:30 +02:00
|
|
|
Retourne la liste de toutes les formations (tous départements,
|
|
|
|
sauf si route départementale).
|
2024-07-27 13:30:02 +02:00
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formations;
|
|
|
|
|
2022-06-17 15:46:17 +02:00
|
|
|
"""
|
2022-07-27 16:03:14 +02:00
|
|
|
query = Formation.query
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
|
2023-04-06 16:10:32 +02:00
|
|
|
return [d.to_dict() for d in query]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2022-07-19 22:17:10 +02:00
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
@bp.route("/formations_ids")
|
|
|
|
@api_web_bp.route("/formations_ids")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2022-05-03 13:35:17 +02:00
|
|
|
def formations_ids():
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2024-03-19 09:34:03 +01:00
|
|
|
Retourne la liste de toutes les id de formations
|
|
|
|
(tous départements, ou du département indiqué dans la route)
|
2022-04-27 14:11:06 +02:00
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
Exemple de résultat : `[ 17, 99, 32 ]`.
|
2024-07-27 13:30:02 +02:00
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formations_ids;
|
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-07-27 16:03:14 +02:00
|
|
|
query = Formation.query
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.filter_by(dept_id=g.scodoc_dept_id)
|
2023-04-06 16:10:32 +02:00
|
|
|
return [d.id for d in query]
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
@bp.route("/formation/<int:formation_id>")
|
|
|
|
@api_web_bp.route("/formation/<int:formation_id>")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2024-07-27 13:30:02 +02:00
|
|
|
def formation_get(formation_id: int):
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2024-07-24 17:34:30 +02:00
|
|
|
La formation d'id donné.
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2024-07-27 13:30:02 +02:00
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formation/1;
|
2022-04-27 14:11:06 +02:00
|
|
|
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-07-27 16:03:14 +02:00
|
|
|
query = Formation.query.filter_by(id=formation_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.filter_by(dept_id=g.scodoc_dept_id)
|
2023-04-06 16:10:32 +02:00
|
|
|
return query.first_or_404().to_dict()
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-05-03 13:35:17 +02:00
|
|
|
@bp.route(
|
2022-07-27 16:03:14 +02:00
|
|
|
"/formation/<int:formation_id>/export",
|
2022-05-03 13:35:17 +02:00
|
|
|
defaults={"export_ids": False},
|
|
|
|
)
|
|
|
|
@bp.route(
|
2022-07-29 16:19:40 +02:00
|
|
|
"/formation/<int:formation_id>/export_with_ids",
|
2022-05-03 13:35:17 +02:00
|
|
|
defaults={"export_ids": True},
|
|
|
|
)
|
2022-07-27 16:03:14 +02:00
|
|
|
@api_web_bp.route(
|
|
|
|
"/formation/<int:formation_id>/export",
|
|
|
|
defaults={"export_ids": False},
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2022-07-29 16:19:40 +02:00
|
|
|
"/formation/<int:formation_id>/export_with_ids",
|
2022-07-27 16:03:14 +02:00
|
|
|
defaults={"export_ids": True},
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2022-03-02 16:45:47 +01:00
|
|
|
def formation_export_by_formation_id(formation_id: int, export_ids=False):
|
|
|
|
"""
|
|
|
|
Retourne la formation, avec UE, matières, modules
|
2022-04-27 14:11:06 +02:00
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
PARAMS
|
|
|
|
------
|
2022-04-27 14:11:06 +02:00
|
|
|
formation_id : l'id d'une formation
|
2024-07-24 17:34:30 +02:00
|
|
|
export_with_ids : si présent, exporte aussi les ids des objets ScoDoc de la formation.
|
2022-04-27 14:11:06 +02:00
|
|
|
|
2024-07-27 13:30:02 +02:00
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formation/1/export
|
2022-03-02 16:45:47 +01:00
|
|
|
"""
|
2022-07-27 16:03:14 +02:00
|
|
|
query = Formation.query.filter_by(id=formation_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
formation = query.first_or_404(formation_id)
|
2022-07-19 22:17:10 +02:00
|
|
|
app.set_sco_dept(formation.departement.acronym)
|
2022-03-02 16:45:47 +01:00
|
|
|
try:
|
2022-05-03 13:35:17 +02:00
|
|
|
data = sco_formations.formation_export(formation_id, export_ids)
|
2022-03-02 16:45:47 +01:00
|
|
|
except ValueError:
|
2022-08-07 19:56:25 +02:00
|
|
|
return json_error(500, message="Erreur inconnue")
|
2022-03-02 16:45:47 +01:00
|
|
|
|
2023-04-06 16:10:32 +02:00
|
|
|
return data
|
2022-03-02 16:45:47 +01:00
|
|
|
|
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
@bp.route("/formation/<int:formation_id>/referentiel_competences")
|
|
|
|
@api_web_bp.route("/formation/<int:formation_id>/referentiel_competences")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2022-07-27 16:03:14 +02:00
|
|
|
def referentiel_competences(formation_id: int):
|
|
|
|
"""
|
2024-07-24 17:34:30 +02:00
|
|
|
Retourne le référentiel de compétences de la formation
|
|
|
|
ou null si pas de référentiel associé.
|
2024-07-27 13:30:02 +02:00
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formation/1/referentiel_competences;
|
|
|
|
|
2022-07-27 16:03:14 +02:00
|
|
|
"""
|
|
|
|
query = Formation.query.filter_by(id=formation_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
formation = query.first_or_404(formation_id)
|
|
|
|
if formation.referentiel_competence is None:
|
2023-04-06 16:10:32 +02:00
|
|
|
return None
|
|
|
|
return formation.referentiel_competence.to_dict()
|
2022-07-27 16:03:14 +02:00
|
|
|
|
|
|
|
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route("/formation/ue/<int:ue_id>/set_parcours", methods=["POST"])
|
|
|
|
@api_web_bp.route("/formation/ue/<int:ue_id>/set_parcours", methods=["POST"])
|
2023-04-03 17:46:31 +02:00
|
|
|
@login_required
|
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.EditFormation)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2024-07-17 14:58:49 +02:00
|
|
|
def ue_set_parcours(ue_id: int):
|
2023-04-03 17:46:31 +02:00
|
|
|
"""Associe UE et parcours BUT.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
2023-04-03 17:46:31 +02:00
|
|
|
La liste des ids de parcours est passée en argument JSON.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
DATA
|
|
|
|
----
|
|
|
|
```json
|
|
|
|
[ parcour_id1, parcour_id2, ... ]
|
|
|
|
```
|
2023-04-03 17:46:31 +02:00
|
|
|
"""
|
|
|
|
query = UniteEns.query.filter_by(id=ue_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
ue: UniteEns = query.first_or_404()
|
|
|
|
parcours_ids = request.get_json(force=True) or [] # may raise 400 Bad Request
|
|
|
|
if parcours_ids == [""]:
|
|
|
|
parcours = []
|
|
|
|
else:
|
|
|
|
parcours = [
|
|
|
|
ApcParcours.query.get_or_404(int(parcour_id)) for parcour_id in parcours_ids
|
|
|
|
]
|
2024-07-17 14:58:49 +02:00
|
|
|
log(f"ue_set_parcours: ue_id={ue.id} parcours_ids={parcours_ids}")
|
2023-04-03 17:46:31 +02:00
|
|
|
ok, error_message = ue.set_parcours(parcours)
|
2023-04-19 11:56:33 +02:00
|
|
|
if not ok:
|
|
|
|
return json_error(404, error_message)
|
2023-04-06 16:10:32 +02:00
|
|
|
return {"status": ok, "message": error_message}
|
2023-04-10 11:25:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/assoc_niveau/<int:niveau_id>",
|
2023-04-10 11:25:46 +02:00
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/assoc_niveau/<int:niveau_id>",
|
2023-04-10 11:25:46 +02:00
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.EditFormation)
|
2023-04-10 11:25:46 +02:00
|
|
|
@as_json
|
2024-07-17 14:58:49 +02:00
|
|
|
def ue_assoc_niveau(ue_id: int, niveau_id: int):
|
2024-07-24 17:34:30 +02:00
|
|
|
"""Associe l'UE au niveau de compétence."""
|
2023-04-10 11:25:46 +02:00
|
|
|
query = UniteEns.query.filter_by(id=ue_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
ue: UniteEns = query.first_or_404()
|
|
|
|
niveau: ApcNiveau = ApcNiveau.query.get_or_404(niveau_id)
|
|
|
|
ok, error_message = ue.set_niveau_competence(niveau)
|
|
|
|
if not ok:
|
|
|
|
if g.scodoc_dept: # "usage web"
|
2023-04-13 09:58:38 +02:00
|
|
|
flash(error_message, "error")
|
2023-04-10 11:25:46 +02:00
|
|
|
return json_error(404, error_message)
|
|
|
|
if g.scodoc_dept: # "usage web"
|
2023-04-13 09:58:38 +02:00
|
|
|
flash(f"""{ue.acronyme} associée au niveau "{niveau.libelle}" """)
|
2023-04-10 11:25:46 +02:00
|
|
|
return {"status": 0}
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/desassoc_niveau",
|
2023-04-10 11:25:46 +02:00
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/desassoc_niveau",
|
2023-04-10 11:25:46 +02:00
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.EditFormation)
|
2023-04-10 11:25:46 +02:00
|
|
|
@as_json
|
2024-07-17 14:58:49 +02:00
|
|
|
def ue_desassoc_niveau(ue_id: int):
|
2023-04-10 11:25:46 +02:00
|
|
|
"""Désassocie cette UE de son niveau de compétence
|
2024-07-24 17:34:30 +02:00
|
|
|
(si elle n'est pas associée, ne fait rien).
|
2023-04-10 11:25:46 +02:00
|
|
|
"""
|
|
|
|
query = UniteEns.query.filter_by(id=ue_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
ue: UniteEns = query.first_or_404()
|
2024-07-08 12:33:48 +02:00
|
|
|
ok, error_message = ue.set_niveau_competence(None)
|
|
|
|
if not ok:
|
|
|
|
if g.scodoc_dept: # "usage web"
|
|
|
|
flash(error_message, "error")
|
|
|
|
return json_error(404, error_message)
|
|
|
|
if g.scodoc_dept: # "usage web"
|
2023-04-10 11:25:46 +02:00
|
|
|
flash(f"UE {ue.acronyme} dé-associée")
|
|
|
|
return {"status": 0}
|
2024-06-21 00:53:52 +02:00
|
|
|
|
|
|
|
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route("/formation/ue/<int:ue_id>", methods=["GET"])
|
|
|
|
@api_web_bp.route("/formation/ue/<int:ue_id>", methods=["GET"])
|
2024-06-21 00:53:52 +02:00
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
def get_ue(ue_id: int):
|
2024-07-27 13:30:02 +02:00
|
|
|
"""Renvoie l'UE.
|
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formation/ue/1;
|
|
|
|
"""
|
2024-06-21 00:53:52 +02:00
|
|
|
query = UniteEns.query.filter_by(id=ue_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
ue: UniteEns = query.first_or_404()
|
|
|
|
return ue.to_dict(convert_objects=True)
|
|
|
|
|
|
|
|
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route("/formation/module/<int:module_id>", methods=["GET"])
|
|
|
|
@api_web_bp.route("/formation/module/<int:module_id>", methods=["GET"])
|
2024-06-21 00:53:52 +02:00
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2024-07-17 14:58:49 +02:00
|
|
|
def formation_module_get(module_id: int):
|
2024-07-27 13:30:02 +02:00
|
|
|
"""Renvoie le module.
|
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/formation/module/1;
|
|
|
|
"""
|
2024-06-21 00:53:52 +02:00
|
|
|
query = Module.query.filter_by(id=module_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
module: Module = query.first_or_404()
|
|
|
|
return module.to_dict(convert_objects=True)
|
|
|
|
|
|
|
|
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route("/formation/ue/set_code_apogee", methods=["POST"])
|
2024-07-17 14:58:49 +02:00
|
|
|
@api_web_bp.route("/formation/ue/set_code_apogee", methods=["POST"])
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route(
|
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee/<string:code_apogee>", methods=["POST"]
|
|
|
|
)
|
2024-06-21 00:53:52 +02:00
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee/<string:code_apogee>", methods=["POST"]
|
2024-06-21 00:53:52 +02:00
|
|
|
)
|
|
|
|
@bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee",
|
|
|
|
defaults={"code_apogee": ""},
|
|
|
|
methods=["POST"],
|
2024-06-21 00:53:52 +02:00
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee",
|
|
|
|
defaults={"code_apogee": ""},
|
|
|
|
methods=["POST"],
|
2024-06-21 00:53:52 +02:00
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.EditFormation)
|
2024-06-24 03:37:40 +02:00
|
|
|
def ue_set_code_apogee(ue_id: int | None = None, code_apogee: str = ""):
|
2024-06-21 00:53:52 +02:00
|
|
|
"""Change le code Apogée de l'UE.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
2024-06-21 00:53:52 +02:00
|
|
|
Le code est une chaîne, avec éventuellement plusieurs valeurs séparées
|
|
|
|
par des virgules.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
Ce changement peut être fait sur formation verrouillée.
|
2024-06-21 00:53:52 +02:00
|
|
|
|
2024-07-25 10:42:49 +02:00
|
|
|
Si `ue_id` n'est pas spécifié, utilise l'argument oid du POST.
|
|
|
|
Si `code_apogee` n'est pas spécifié ou vide,
|
2024-07-24 17:34:30 +02:00
|
|
|
utilise l'argument value du POST.
|
2024-06-21 00:53:52 +02:00
|
|
|
|
2024-07-25 10:42:49 +02:00
|
|
|
Le retour est une chaîne (le code enregistré), pas du json.
|
2024-06-21 00:53:52 +02:00
|
|
|
"""
|
2024-06-24 03:37:40 +02:00
|
|
|
if ue_id is None:
|
|
|
|
ue_id = request.form.get("oid")
|
|
|
|
if ue_id is None:
|
|
|
|
return json_error(404, "argument oid manquant")
|
2024-06-21 00:53:52 +02:00
|
|
|
if not code_apogee:
|
|
|
|
code_apogee = request.form.get("value", "")
|
|
|
|
query = UniteEns.query.filter_by(id=ue_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
ue: UniteEns = query.first_or_404()
|
|
|
|
|
|
|
|
code_apogee = code_apogee.strip("-_ \t")[:APO_CODE_STR_LEN] # tronque
|
|
|
|
|
|
|
|
log(f"API ue_set_code_apogee: ue_id={ue.id} code_apogee={code_apogee}")
|
|
|
|
|
|
|
|
ue.code_apogee = code_apogee
|
|
|
|
db.session.add(ue)
|
|
|
|
db.session.commit()
|
|
|
|
return code_apogee or ""
|
|
|
|
|
|
|
|
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route(
|
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee_rcue/<string:code_apogee>",
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
2024-06-21 00:53:52 +02:00
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee_rcue/<string:code_apogee>",
|
|
|
|
methods=["POST"],
|
2024-06-21 00:53:52 +02:00
|
|
|
)
|
|
|
|
@bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee_rcue",
|
2024-06-21 00:53:52 +02:00
|
|
|
defaults={"code_apogee": ""},
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/ue/<int:ue_id>/set_code_apogee_rcue",
|
2024-06-21 00:53:52 +02:00
|
|
|
defaults={"code_apogee": ""},
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.EditFormation)
|
|
|
|
def ue_set_code_apogee_rcue(ue_id: int, code_apogee: str = ""):
|
|
|
|
"""Change le code Apogée du RCUE de l'UE.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
2024-06-21 00:53:52 +02:00
|
|
|
Le code est une chaîne, avec éventuellement plusieurs valeurs séparées
|
|
|
|
par des virgules.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
Ce changement peut être fait sur formation verrouillée.
|
2024-06-21 00:53:52 +02:00
|
|
|
|
|
|
|
Si code_apogee n'est pas spécifié ou vide,
|
2024-07-25 10:42:49 +02:00
|
|
|
utilise l'argument value du POST (utilisé par `jinplace.js`)
|
2024-06-21 00:53:52 +02:00
|
|
|
|
2024-07-25 10:42:49 +02:00
|
|
|
Le retour est une chaîne (le code enregistré), pas du json.
|
2024-06-21 00:53:52 +02:00
|
|
|
"""
|
|
|
|
if not code_apogee:
|
|
|
|
code_apogee = request.form.get("value", "")
|
|
|
|
query = UniteEns.query.filter_by(id=ue_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
ue: UniteEns = query.first_or_404()
|
|
|
|
|
|
|
|
code_apogee = code_apogee.strip("-_ \t")[:APO_CODE_STR_LEN] # tronque
|
|
|
|
|
|
|
|
log(f"API ue_set_code_apogee_rcue: ue_id={ue.id} code_apogee={code_apogee}")
|
|
|
|
|
|
|
|
ue.code_apogee_rcue = code_apogee
|
|
|
|
db.session.add(ue)
|
|
|
|
db.session.commit()
|
|
|
|
return code_apogee or ""
|
|
|
|
|
|
|
|
|
2024-07-03 21:32:33 +02:00
|
|
|
@bp.route("/formation/module/set_code_apogee", methods=["POST"])
|
|
|
|
@api_web_bp.route("/formation/module/set_code_apogee", methods=["POST"])
|
2024-06-21 00:53:52 +02:00
|
|
|
@bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/module/<int:module_id>/set_code_apogee/<string:code_apogee>",
|
2024-06-21 00:53:52 +02:00
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/module/<int:module_id>/set_code_apogee/<string:code_apogee>",
|
2024-06-21 00:53:52 +02:00
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/module/<int:module_id>/set_code_apogee",
|
2024-06-21 00:53:52 +02:00
|
|
|
defaults={"code_apogee": ""},
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
2024-07-03 21:32:33 +02:00
|
|
|
"/formation/module/<int:module_id>/set_code_apogee",
|
2024-06-21 00:53:52 +02:00
|
|
|
defaults={"code_apogee": ""},
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.EditFormation)
|
2024-07-17 14:58:49 +02:00
|
|
|
def formation_module_set_code_apogee(
|
|
|
|
module_id: int | None = None, code_apogee: str = ""
|
|
|
|
):
|
2024-06-21 00:53:52 +02:00
|
|
|
"""Change le code Apogée du module.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
2024-06-21 00:53:52 +02:00
|
|
|
Le code est une chaîne, avec éventuellement plusieurs valeurs séparées
|
|
|
|
par des virgules.
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
Ce changement peut être fait sur formation verrouillée.
|
2024-06-21 00:53:52 +02:00
|
|
|
|
2024-07-25 10:42:49 +02:00
|
|
|
Si `module_id` n'est pas spécifié, utilise l'argument `oid` du POST.
|
|
|
|
Si `code_apogee` n'est pas spécifié ou vide,
|
2024-06-21 00:53:52 +02:00
|
|
|
utilise l'argument value du POST (utilisé par jinplace.js)
|
|
|
|
|
2024-07-25 10:42:49 +02:00
|
|
|
Le retour est une chaîne (le code enregistré), pas du json.
|
2024-06-21 00:53:52 +02:00
|
|
|
"""
|
2024-06-24 03:37:40 +02:00
|
|
|
if module_id is None:
|
|
|
|
module_id = request.form.get("oid")
|
|
|
|
if module_id is None:
|
|
|
|
return json_error(404, "argument oid manquant")
|
2024-06-21 00:53:52 +02:00
|
|
|
if not code_apogee:
|
|
|
|
code_apogee = request.form.get("value", "")
|
|
|
|
query = Module.query.filter_by(id=module_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
module: Module = query.first_or_404()
|
|
|
|
|
|
|
|
code_apogee = code_apogee.strip("-_ \t")[:APO_CODE_STR_LEN] # tronque
|
|
|
|
|
2024-07-18 16:54:48 +02:00
|
|
|
log(
|
|
|
|
f"API formation_module_set_code_apogee: module_id={module.id} code_apogee={code_apogee}"
|
|
|
|
)
|
2024-06-21 00:53:52 +02:00
|
|
|
|
|
|
|
module.code_apogee = code_apogee
|
|
|
|
db.session.add(module)
|
|
|
|
db.session.commit()
|
|
|
|
return code_apogee or ""
|
2024-07-03 21:32:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
|
|
|
"/formation/module/<int:module_id>/edit",
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
|
|
|
"/formation/module/<int:module_id>/edit",
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.EditFormation)
|
|
|
|
@as_json
|
2024-07-17 14:58:49 +02:00
|
|
|
def formation_module_edit(module_id: int):
|
2024-07-03 21:32:33 +02:00
|
|
|
"""Édition d'un module. Renvoie le module en json."""
|
|
|
|
query = Module.query.filter_by(id=module_id)
|
|
|
|
if g.scodoc_dept:
|
|
|
|
query = query.join(Formation).filter_by(dept_id=g.scodoc_dept_id)
|
|
|
|
module: Module = query.first_or_404()
|
|
|
|
args = request.get_json(force=True) # may raise 400 Bad Request
|
|
|
|
module.from_dict(args)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(module)
|
|
|
|
log(f"API module_edit: module_id={module.id} args={args}")
|
|
|
|
r = module.to_dict(convert_objects=True, with_parcours_ids=True)
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
|
|
|
"/formation/ue/<int:ue_id>/edit",
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@api_web_bp.route(
|
|
|
|
"/formation/ue/<int:ue_id>/edit",
|
|
|
|
methods=["POST"],
|
|
|
|
)
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.EditFormation)
|
|
|
|
@as_json
|
|
|
|
def ue_edit(ue_id: int):
|
|
|
|
"""Édition d'une UE. Renvoie l'UE en json."""
|
|
|
|
ue = UniteEns.get_ue(ue_id)
|
|
|
|
args = request.get_json(force=True) # may raise 400 Bad Request
|
|
|
|
ue.from_dict(args)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(ue)
|
|
|
|
log(f"API ue_edit: ue_id={ue.id} args={args}")
|
|
|
|
r = ue.to_dict(convert_objects=True)
|
|
|
|
return r
|