2023-08-26 16:34:56 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2023-08-26 16:34:56 +02:00
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
ScoDoc 9 API : accès aux moduleimpl
|
2024-07-24 17:34:30 +02:00
|
|
|
|
|
|
|
CATEGORY
|
|
|
|
--------
|
|
|
|
ModuleImpl
|
2023-08-26 16:34:56 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
from flask_json import as_json
|
|
|
|
from flask_login import login_required
|
|
|
|
|
2024-01-23 22:55:00 +01:00
|
|
|
import app
|
2024-08-06 22:30:30 +02:00
|
|
|
from app import db
|
2023-08-26 16:34:56 +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-08-06 22:30:30 +02:00
|
|
|
from app.models import Identite, ModuleImpl, ModuleImplInscription
|
|
|
|
from app.scodoc import sco_cache, sco_liste_notes
|
|
|
|
from app.scodoc.sco_moduleimpl import do_moduleimpl_inscrit_etuds
|
2023-08-26 16:34:56 +02:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2024-08-06 22:30:30 +02:00
|
|
|
from app.scodoc.sco_utils import json_error
|
2023-08-26 16:34:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/moduleimpl/<int:moduleimpl_id>")
|
|
|
|
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
@as_json
|
|
|
|
def moduleimpl(moduleimpl_id: int):
|
|
|
|
"""
|
2024-07-24 17:34:30 +02:00
|
|
|
Retourne le moduleimpl.
|
2023-08-26 16:34:56 +02:00
|
|
|
|
2024-07-24 17:34:30 +02:00
|
|
|
PARAMS
|
|
|
|
------
|
2023-08-26 16:34:56 +02:00
|
|
|
moduleimpl_id : l'id d'un moduleimpl
|
|
|
|
|
2024-07-27 13:30:02 +02:00
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/moduleimpl/1
|
2023-08-26 16:34:56 +02:00
|
|
|
"""
|
2024-01-23 22:55:00 +01:00
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
2023-08-26 16:34:56 +02:00
|
|
|
return modimpl.to_dict(convert_objects=True)
|
2023-09-20 12:45:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/moduleimpl/<int:moduleimpl_id>/inscriptions")
|
|
|
|
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/inscriptions")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
@as_json
|
|
|
|
def moduleimpl_inscriptions(moduleimpl_id: int):
|
2024-07-24 17:34:30 +02:00
|
|
|
"""Liste des inscriptions à ce moduleimpl.
|
|
|
|
|
2024-07-27 13:30:02 +02:00
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/moduleimpl/1/inscriptions
|
2023-09-20 12:45:24 +02:00
|
|
|
"""
|
2024-01-23 22:55:00 +01:00
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
2023-09-20 12:45:24 +02:00
|
|
|
return [i.to_dict() for i in modimpl.inscriptions]
|
2024-01-23 22:55:00 +01:00
|
|
|
|
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
@bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/inscrit")
|
|
|
|
@api_web_bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/inscrit")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
@as_json
|
|
|
|
def moduleimpl_etud_inscrit(moduleimpl_id: int, etudid: int):
|
|
|
|
"""Inscrit l'étudiant à ce moduleimpl.
|
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/moduleimpl/1/etudid/2/inscrit
|
|
|
|
"""
|
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
|
|
|
if not modimpl.can_change_inscriptions():
|
|
|
|
return json_error(403, "opération non autorisée")
|
|
|
|
etud = Identite.get_etud(etudid)
|
|
|
|
do_moduleimpl_inscrit_etuds(modimpl.id, modimpl.formsemestre_id, [etud.id])
|
|
|
|
app.log(f"moduleimpl_etud_inscrit: {etud} inscrit à {modimpl}")
|
|
|
|
return (
|
|
|
|
ModuleImplInscription.query.filter_by(moduleimpl_id=modimpl.id, etudid=etud.id)
|
|
|
|
.first()
|
|
|
|
.to_dict()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/desinscrit")
|
|
|
|
@api_web_bp.post("/moduleimpl/<int:moduleimpl_id>/etudid/<int:etudid>/desinscrit")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
@as_json
|
|
|
|
def moduleimpl_etud_desinscrit(moduleimpl_id: int, etudid: int):
|
|
|
|
"""Désinscrit l'étudiant de ce moduleimpl.
|
|
|
|
|
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/moduleimpl/1/etudid/2/desinscrit
|
|
|
|
"""
|
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
|
|
|
if not modimpl.can_change_inscriptions():
|
|
|
|
return json_error(403, "opération non autorisée")
|
|
|
|
etud = Identite.get_etud(etudid)
|
|
|
|
inscription = ModuleImplInscription.query.filter_by(
|
|
|
|
etudid=etud.id, moduleimpl_id=modimpl.id
|
|
|
|
).first()
|
|
|
|
if inscription:
|
|
|
|
db.session.delete(inscription)
|
|
|
|
db.session.commit()
|
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=modimpl.formsemestre_id)
|
|
|
|
app.log(f"moduleimpl_etud_desinscrit: {etud} inscrit à {modimpl}")
|
|
|
|
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
2024-01-23 22:55:00 +01:00
|
|
|
@bp.route("/moduleimpl/<int:moduleimpl_id>/notes")
|
|
|
|
@api_web_bp.route("/moduleimpl/<int:moduleimpl_id>/notes")
|
|
|
|
@login_required
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
def moduleimpl_notes(moduleimpl_id: int):
|
2024-07-25 10:42:49 +02:00
|
|
|
"""Liste des notes dans ce moduleimpl.
|
|
|
|
|
2024-07-27 13:30:02 +02:00
|
|
|
SAMPLES
|
|
|
|
-------
|
|
|
|
/moduleimpl/1/notes
|
2024-01-23 22:55:00 +01:00
|
|
|
"""
|
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
|
|
|
app.set_sco_dept(modimpl.formsemestre.departement.acronym)
|
|
|
|
table, _ = sco_liste_notes.do_evaluation_listenotes(
|
|
|
|
moduleimpl_id=modimpl.id, fmt="json"
|
|
|
|
)
|
|
|
|
return table
|