From 72457a0651c3fd698575a2e7edd445684df77c7b Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 18 Feb 2023 00:13:00 +0100 Subject: [PATCH] =?UTF-8?q?Modernisation=20d'une=20partie=20des=20acc?= =?UTF-8?q?=C3=A8s=20aux=20formations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/formations.py | 4 ++- app/pe/pe_jurype.py | 8 ++--- app/scodoc/sco_bulletins.py | 11 ++---- app/scodoc/sco_cursus_dut.py | 4 +-- app/scodoc/sco_edit_formation.py | 36 +++++++++---------- app/scodoc/sco_edit_matiere.py | 6 ++-- app/scodoc/sco_edit_module.py | 24 ++++++++----- app/scodoc/sco_etape_apogee_view.py | 23 +++++++------ app/scodoc/sco_export_results.py | 6 ++-- app/scodoc/sco_formations.py | 12 +++---- app/scodoc/sco_formsemestre.py | 13 +++---- app/scodoc/sco_formsemestre_edit.py | 8 +++-- app/scodoc/sco_formsemestre_exterieurs.py | 8 ++--- app/scodoc/sco_formsemestre_status.py | 5 +-- app/scodoc/sco_formsemestre_validation.py | 42 +++++++++++++---------- app/scodoc/sco_pvjury.py | 10 +++--- app/views/notes.py | 26 -------------- tests/unit/test_formations.py | 38 +++++++++----------- 18 files changed, 119 insertions(+), 165 deletions(-) diff --git a/app/models/formations.py b/app/models/formations.py index 15dae9d5..e2eadf46 100644 --- a/app/models/formations.py +++ b/app/models/formations.py @@ -71,6 +71,8 @@ class Formation(db.Model): e.pop("_sa_instance_state", None) if "referentiel_competence" in e: e.pop("referentiel_competence") + e["code_specialite"] = e["code_specialite"] or "" + e["commentaire"] = e["commentaire"] or "" e["departement"] = self.departement.to_dict() e["formation_id"] = self.id # ScoDoc7 backward compat if with_refcomp_attrs and self.referentiel_competence: @@ -289,6 +291,6 @@ class Matiere(db.Model): e = dict(self.__dict__) e.pop("_sa_instance_state", None) # ScoDoc7 output_formators - e["ue_id"] = self.id e["numero"] = e["numero"] if e["numero"] else 0 + e["ue_id"] = self.id return e diff --git a/app/pe/pe_jurype.py b/app/pe/pe_jurype.py index 5c85c253..f55623d3 100644 --- a/app/pe/pe_jurype.py +++ b/app/pe/pe_jurype.py @@ -48,7 +48,7 @@ from zipfile import ZipFile from app.comp import res_sem from app.comp.res_compat import NotesTableCompat -from app.models import FormSemestre +from app.models import Formation, FormSemestre from app.scodoc.gen_tables import GenTable, SeqGenTable import app.scodoc.sco_utils as scu @@ -65,10 +65,8 @@ def comp_nom_semestre_dans_parcours(sem): """Le nom a afficher pour titrer un semestre par exemple: "semestre 2 FI 2015" """ - from app.scodoc import sco_formations - - F = sco_formations.formation_list(args={"formation_id": sem["formation_id"]})[0] - parcours = codes_cursus.get_cursus_from_code(F["type_parcours"]) + formation: Formation = Formation.query.get_or_404(sem["formation_id"]) + parcours = codes_cursus.get_cursus_from_code(formation.type_parcours) return "%s %s %s %s" % ( parcours.SESSION_NAME, # eg "semestre" sem["semestre_id"], # eg 2 diff --git a/app/scodoc/sco_bulletins.py b/app/scodoc/sco_bulletins.py index 67ba9851..cef2c73e 100644 --- a/app/scodoc/sco_bulletins.py +++ b/app/scodoc/sco_bulletins.py @@ -42,7 +42,7 @@ from app.scodoc.sco_utils import json_error from app.but import bulletin_but from app.comp import res_sem from app.comp.res_compat import NotesTableCompat -from app.models import FormSemestre, Identite, ModuleImplInscription +from app.models import Formation, FormSemestre, Identite, ModuleImplInscription from app.scodoc.sco_permissions import Permission from app.scodoc.sco_exceptions import AccessDenied, ScoValueError from app.scodoc import html_sco_header @@ -152,14 +152,9 @@ def formsemestre_bulletinetud_dict(formsemestre_id, etudid, version="long"): I["server_name"] = request.url_root # Formation et parcours - formation_dict = None if I["sem"]["formation_id"]: - formation_dicts = sco_formations.formation_list( - args={"formation_id": I["sem"]["formation_id"]} - ) - if formation_dicts: - formation_dict = formation_dicts[0] - if formation_dict is None: # what's the fuck ? + formation_dict = Formation.query.get_or_404(I["sem"]["formation_id"]).to_dict() + else: # what's the fuck ? formation_dict = { "acronyme": "?", "code_specialite": "", diff --git a/app/scodoc/sco_cursus_dut.py b/app/scodoc/sco_cursus_dut.py index 5b5b3c65..babaede7 100644 --- a/app/scodoc/sco_cursus_dut.py +++ b/app/scodoc/sco_cursus_dut.py @@ -336,9 +336,7 @@ class SituationEtudCursusClassic(SituationEtudCursus): if nb_ue > nb_max_ue: nb_max_ue = nb_ue # add formation_code to each sem: - sem["formation_code"] = sco_formations.formation_list( - args={"formation_id": sem["formation_id"]} - )[0]["formation_code"] + sem["formation_code"] = formsemestre.formation.formation_code # si sem peut servir à compenser le semestre courant, positionne # can_compensate sem["can_compensate"] = self.check_compensation_dut(sem, nt) diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 2d2e348a..14be5a28 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -54,14 +54,11 @@ from app.scodoc import sco_formsemestre def formation_delete(formation_id=None, dialog_confirmed=False): """Delete a formation""" - F = sco_formations.formation_list(args={"formation_id": formation_id}) - if not F: - raise ScoValueError("formation inexistante !") - F = F[0] + formation: Formation = Formation.query.get_or_404(formation_id) H = [ html_sco_header.sco_header(page_title="Suppression d'une formation"), - """

Suppression de la formation %(titre)s (%(acronyme)s)

""" % F, + f"""

Suppression de la formation {formation.titre} ({formation.acronyme})

""", ] sems = sco_formsemestre.do_formsemestre_list({"formation_id": formation_id}) @@ -80,21 +77,22 @@ def formation_delete(formation_id=None, dialog_confirmed=False): else: if not dialog_confirmed: return scu.confirm_dialog( - """

Confirmer la suppression de la formation %(titre)s (%(acronyme)s) ?

-

Attention: la suppression d'une formation est irréversible et implique la supression de toutes les UE, matières et modules de la formation ! -

- """ - % F, + f"""

Confirmer la suppression de la formation + {formation.titre} ({formation.acronyme}) ? +

+

Attention: la suppression d'une formation est irréversible + et implique la supression de toutes les UE, matières et modules de la formation ! +

+ """, OK="Supprimer cette formation", cancel_url=scu.NotesURL(), parameters={"formation_id": formation_id}, ) else: - do_formation_delete(F["formation_id"]) + do_formation_delete(formation_id) H.append( - """

OK, formation supprimée.

-

continuer

""" - % scu.NotesURL() + f"""

OK, formation supprimée.

+

continuer

""" ) H.append(html_sco_header.sco_footer()) @@ -271,7 +269,7 @@ def formation_edit(formation_id=None, create=False): + tf_error_message( f"""Valeurs incorrectes: il existe déjà une formation avec même titre, + }">une formation avec même titre, acronyme et version. """ ) @@ -297,10 +295,10 @@ def do_formation_create(args): a = args.copy() if "formation_id" in a: del a["formation_id"] - F = sco_formations.formation_list(args=a) - if len(F) > 0: - log("do_formation_create: error: %d formations matching args=%s" % (len(F), a)) - raise ScoValueError("Formation non unique (%s) !" % str(a)) + f_dicts = sco_formations.formation_list(args=a) + if len(f_dicts) > 0: + log(f"do_formation_create: error: {len(f_dicts)} formations matching args={a}") + raise ScoValueError(f"Formation non unique ({a}) !") # Si pas de formation_code, l'enleve (default SQL) if "formation_code" in args and not args["formation_code"]: del args["formation_code"] diff --git a/app/scodoc/sco_edit_matiere.py b/app/scodoc/sco_edit_matiere.py index f0f2ce5b..312f01ec 100644 --- a/app/scodoc/sco_edit_matiere.py +++ b/app/scodoc/sco_edit_matiere.py @@ -253,7 +253,6 @@ def matiere_delete(matiere_id=None): def matiere_edit(matiere_id=None): """Edit matiere""" - from app.scodoc import sco_formations from app.scodoc import sco_edit_ue F = matiere_list(args={"matiere_id": matiere_id}) @@ -264,15 +263,14 @@ def matiere_edit(matiere_id=None): if not ues: raise ScoValueError("UE inexistante !") ue = ues[0] - Fo = sco_formations.formation_list(args={"formation_id": ue["formation_id"]})[0] - + formation: Formation = Formation.query.get_or_404(ue["formation_id"]) ues = sco_edit_ue.ue_list(args={"formation_id": ue["formation_id"]}) ue_names = ["%(acronyme)s (%(titre)s)" % u for u in ues] ue_ids = [u["ue_id"] for u in ues] H = [ html_sco_header.sco_header(page_title="Modification d'une matière"), """

Modification de la matière %(titre)s""" % F, - """(formation %(acronyme)s, version %(version)s)

""" % Fo, + f"""(formation ({formation.acronyme}, version {formation.version})""", ] help = """

Les matières sont des groupes de modules dans une UE d'une formation donnée. Les matières servent surtout pour la diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index 4bbd4911..5014435d 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -900,21 +900,27 @@ def module_table(formation_id): if not formation_id: raise ScoValueError("invalid formation !") - F = sco_formations.formation_list(args={"formation_id": formation_id})[0] + formation: Formation = Formation.query.get_or_404(formation_id) H = [ - html_sco_header.sco_header(page_title="Liste des modules de %(titre)s" % F), - """

Listes des modules dans la formation %(titre)s (%(acronyme)s)

""" - % F, - '