API: decisions_jury pour les formations classiques

This commit is contained in:
Emmanuel Viennet 2024-10-04 08:46:09 +02:00
parent f7f55c2494
commit 908af14e5a
6 changed files with 40 additions and 27 deletions

View File

@ -54,25 +54,22 @@ from app.scodoc.sco_utils import json_error
@as_json @as_json
def decisions_jury(formsemestre_id: int): def decisions_jury(formsemestre_id: int):
"""Décisions du jury des étudiants du formsemestre. """Décisions du jury des étudiants du formsemestre.
(fonction disponible uniquement en BUT actuellement).
SAMPLES SAMPLES
------- -------
/formsemestre/1/decisions_jury /formsemestre/1/decisions_jury
""" """
# APC, pair: # APC, pair:
formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
if formsemestre is None: if formsemestre is None:
return json_error( return json_error(
404, 404,
message="formsemestre inconnu", message="formsemestre inconnu",
) )
if formsemestre.formation.is_apc():
app.set_sco_dept(formsemestre.departement.acronym) app.set_sco_dept(formsemestre.departement.acronym)
rows = jury_but_results.get_jury_but_results(formsemestre) rows = jury_but_results.get_jury_but_results(formsemestre)
return rows return rows
else:
raise ScoException("non implemente")
def _news_delete_jury_etud(etud: Identite, detail: str = ""): def _news_delete_jury_etud(etud: Identite, detail: str = ""):

View File

@ -16,8 +16,11 @@ from app.scodoc import sco_pv_dict
def get_jury_but_results(formsemestre: FormSemestre) -> list[dict]: def get_jury_but_results(formsemestre: FormSemestre) -> list[dict]:
"""Liste des résultats jury BUT sous forme de dict, pour API""" """Liste des résultats jury BUT ou classique sous forme de dict, pour API"""
if formsemestre.formation.referentiel_competence is None: if (
formsemestre.formation.is_apc()
and formsemestre.formation.referentiel_competence is None
):
# pas de ref. comp., donc pas de decisions de jury (ne lance pas d'exception) # pas de ref. comp., donc pas de decisions de jury (ne lance pas d'exception)
return [] return []
dpv = sco_pv_dict.dict_pvjury(formsemestre.id) dpv = sco_pv_dict.dict_pvjury(formsemestre.id)
@ -30,7 +33,7 @@ def get_jury_but_results(formsemestre: FormSemestre) -> list[dict]:
def _get_jury_but_etud_result( def _get_jury_but_etud_result(
formsemestre: FormSemestre, dpv: dict, etudid: int formsemestre: FormSemestre, dpv: dict, etudid: int
) -> dict: ) -> dict:
"""Résultats de jury d'un étudiant sur un semestre pair de BUT""" """Résultats de jury d'un étudiant sur un semestre, sous forme de dict"""
etud = Identite.get_etud(etudid) etud = Identite.get_etud(etudid)
dec_etud = dpv["decisions_dict"][etudid] dec_etud = dpv["decisions_dict"][etudid]
if formsemestre.formation.is_apc(): if formsemestre.formation.is_apc():

View File

@ -202,22 +202,33 @@ class FormSemestre(models.ScoDocModel):
@classmethod @classmethod
def get_formsemestre( def get_formsemestre(
cls, formsemestre_id: int | str, dept_id: int = None cls, formsemestre_id: int | str, dept_id: int = None, accept_none=False
) -> "FormSemestre": ) -> "FormSemestre | None":
"""FormSemestre ou 404, cherche uniquement dans le département spécifié """FormSemestre ou 404 (ou None si accept_none), cherche uniquement dans
ou le courant (g.scodoc_dept)""" le département spécifié ou le courant (g.scodoc_dept).
Si accept_none, return None si l'id est invalide ou ne correspond
pas à un formsemestre.
"""
if not isinstance(formsemestre_id, int): if not isinstance(formsemestre_id, int):
try: try:
formsemestre_id = int(formsemestre_id) formsemestre_id = int(formsemestre_id)
except (TypeError, ValueError): except (TypeError, ValueError):
if accept_none:
return None
abort(404, "formsemestre_id invalide") abort(404, "formsemestre_id invalide")
if g.scodoc_dept:
dept_id = dept_id if dept_id is not None else g.scodoc_dept_id dept_id = (
if dept_id is not None: dept_id
return cls.query.filter_by( if dept_id is not None
id=formsemestre_id, dept_id=dept_id else (g.scodoc_dept_id if g.scodoc_dept else None)
).first_or_404() )
return cls.query.filter_by(id=formsemestre_id).first_or_404()
query = (
cls.query.filter_by(id=formsemestre_id)
if dept_id is None
else cls.query.filter_by(id=formsemestre_id, dept_id=dept_id)
)
return query.first() if accept_none else query.first_or_404()
@classmethod @classmethod
def create_formsemestre(cls, args: dict, silent=False) -> "FormSemestre": def create_formsemestre(cls, args: dict, silent=False) -> "FormSemestre":

View File

@ -53,7 +53,7 @@ import subprocess
import requests import requests
from flask import g, request from flask import current_app, g, request
from flask_login import current_user from flask_login import current_user
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
@ -184,6 +184,7 @@ def _send_db(
"serial": _get_scodoc_serial(), "serial": _get_scodoc_serial(),
"sco_user": str(current_user), "sco_user": str(current_user),
"sent_by": f'"{current_user.get_nomcomplet()}" <{current_user.email}>', "sent_by": f'"{current_user.get_nomcomplet()}" <{current_user.email}>',
"admin_mail": current_app.config.get("SCODOC_ADMIN_MAIL"),
"sco_version": sco_version.SCOVERSION, "sco_version": sco_version.SCOVERSION,
"sco_fullversion": scu.get_scodoc_version(), "sco_fullversion": scu.get_scodoc_version(),
"traceback_str": traceback_str, "traceback_str": traceback_str,

View File

@ -683,9 +683,7 @@ def ue_table(formation_id=None, semestre_idx=1, msg=""): # was ue_list
""" """
from app.scodoc import sco_formsemestre_validation from app.scodoc import sco_formsemestre_validation
formation: Formation = db.session.get(Formation, formation_id) formation = Formation.get_formation(formation_id)
if not formation:
raise ScoValueError("invalid formation_id")
parcours = formation.get_cursus() parcours = formation.get_cursus()
is_apc = parcours.APC_SAE is_apc = parcours.APC_SAE
if semestre_idx == "all" or semestre_idx == "": if semestre_idx == "all" or semestre_idx == "":

View File

@ -218,7 +218,7 @@ def formation_export(
export_external_ues=False, export_external_ues=False,
export_codes_apo=True, export_codes_apo=True,
fmt=None, fmt=None,
) -> flask.Response: ) -> flask.Response | dict:
"""Get a formation, with UE, matieres, modules """Get a formation, with UE, matieres, modules
in desired format in desired format
""" """
@ -233,6 +233,9 @@ def formation_export(
export_codes_apo=export_codes_apo, export_codes_apo=export_codes_apo,
ac_as_list=fmt == "xml", ac_as_list=fmt == "xml",
) )
if fmt is None:
return f_dict
filename = f"scodoc_formation_{formation.departement.acronym}_{formation.acronyme or ''}_v{formation.version}" filename = f"scodoc_formation_{formation.departement.acronym}_{formation.acronyme or ''}_v{formation.version}"
return scu.sendResult( return scu.sendResult(
f_dict, f_dict,