From 908af14e5a919df90287bc24b1582d82a7d62906 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 4 Oct 2024 08:46:09 +0200 Subject: [PATCH] API: decisions_jury pour les formations classiques --- app/api/jury.py | 13 +++++-------- app/but/jury_but_results.py | 9 ++++++--- app/models/formsemestre.py | 33 ++++++++++++++++++++++----------- app/scodoc/sco_dump_db.py | 3 ++- app/scodoc/sco_edit_ue.py | 4 +--- app/scodoc/sco_formations.py | 5 ++++- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/app/api/jury.py b/app/api/jury.py index 190c9aff6..528faa435 100644 --- a/app/api/jury.py +++ b/app/api/jury.py @@ -54,25 +54,22 @@ from app.scodoc.sco_utils import json_error @as_json def decisions_jury(formsemestre_id: int): """Décisions du jury des étudiants du formsemestre. - (fonction disponible uniquement en BUT actuellement). SAMPLES ------- /formsemestre/1/decisions_jury """ # APC, pair: - formsemestre: FormSemestre = db.session.get(FormSemestre, formsemestre_id) + formsemestre = FormSemestre.get_formsemestre(formsemestre_id) if formsemestre is None: return json_error( 404, message="formsemestre inconnu", ) - if formsemestre.formation.is_apc(): - app.set_sco_dept(formsemestre.departement.acronym) - rows = jury_but_results.get_jury_but_results(formsemestre) - return rows - else: - raise ScoException("non implemente") + + app.set_sco_dept(formsemestre.departement.acronym) + rows = jury_but_results.get_jury_but_results(formsemestre) + return rows def _news_delete_jury_etud(etud: Identite, detail: str = ""): diff --git a/app/but/jury_but_results.py b/app/but/jury_but_results.py index 044c96669..d55ea1576 100644 --- a/app/but/jury_but_results.py +++ b/app/but/jury_but_results.py @@ -16,8 +16,11 @@ from app.scodoc import sco_pv_dict def get_jury_but_results(formsemestre: FormSemestre) -> list[dict]: - """Liste des résultats jury BUT sous forme de dict, pour API""" - if formsemestre.formation.referentiel_competence is None: + """Liste des résultats jury BUT ou classique sous forme de dict, pour API""" + 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) return [] 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( formsemestre: FormSemestre, dpv: dict, etudid: int ) -> 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) dec_etud = dpv["decisions_dict"][etudid] if formsemestre.formation.is_apc(): diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 990eea672..4afd6a3f3 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -202,22 +202,33 @@ class FormSemestre(models.ScoDocModel): @classmethod def get_formsemestre( - cls, formsemestre_id: int | str, dept_id: int = None - ) -> "FormSemestre": - """FormSemestre ou 404, cherche uniquement dans le département spécifié - ou le courant (g.scodoc_dept)""" + cls, formsemestre_id: int | str, dept_id: int = None, accept_none=False + ) -> "FormSemestre | None": + """FormSemestre ou 404 (ou None si accept_none), cherche uniquement dans + 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): try: formsemestre_id = int(formsemestre_id) except (TypeError, ValueError): + if accept_none: + return None abort(404, "formsemestre_id invalide") - if g.scodoc_dept: - dept_id = dept_id if dept_id is not None else g.scodoc_dept_id - if dept_id is not None: - return cls.query.filter_by( - id=formsemestre_id, dept_id=dept_id - ).first_or_404() - return cls.query.filter_by(id=formsemestre_id).first_or_404() + + dept_id = ( + dept_id + if dept_id is not None + else (g.scodoc_dept_id if g.scodoc_dept else None) + ) + + 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 def create_formsemestre(cls, args: dict, silent=False) -> "FormSemestre": diff --git a/app/scodoc/sco_dump_db.py b/app/scodoc/sco_dump_db.py index b7a5f8aba..f1f8b1522 100644 --- a/app/scodoc/sco_dump_db.py +++ b/app/scodoc/sco_dump_db.py @@ -53,7 +53,7 @@ import subprocess import requests -from flask import g, request +from flask import current_app, g, request from flask_login import current_user import app.scodoc.notesdb as ndb @@ -184,6 +184,7 @@ def _send_db( "serial": _get_scodoc_serial(), "sco_user": str(current_user), "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_fullversion": scu.get_scodoc_version(), "traceback_str": traceback_str, diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 5dc218e9c..c47cca531 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -683,9 +683,7 @@ def ue_table(formation_id=None, semestre_idx=1, msg=""): # was ue_list """ from app.scodoc import sco_formsemestre_validation - formation: Formation = db.session.get(Formation, formation_id) - if not formation: - raise ScoValueError("invalid formation_id") + formation = Formation.get_formation(formation_id) parcours = formation.get_cursus() is_apc = parcours.APC_SAE if semestre_idx == "all" or semestre_idx == "": diff --git a/app/scodoc/sco_formations.py b/app/scodoc/sco_formations.py index 2fc63a347..e86b371dc 100644 --- a/app/scodoc/sco_formations.py +++ b/app/scodoc/sco_formations.py @@ -218,7 +218,7 @@ def formation_export( export_external_ues=False, export_codes_apo=True, fmt=None, -) -> flask.Response: +) -> flask.Response | dict: """Get a formation, with UE, matieres, modules in desired format """ @@ -233,6 +233,9 @@ def formation_export( export_codes_apo=export_codes_apo, 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}" return scu.sendResult( f_dict,