From 056be2e1524e070979ff4d4e591b5244e864f353 Mon Sep 17 00:00:00 2001 From: ilona Date: Thu, 10 Oct 2024 00:41:20 +0200 Subject: [PATCH] Reorganisation fichiers code formations --- app/api/formations.py | 4 +- .../edit_formation.py} | 4 +- .../edit_matiere.py} | 33 +++++----- .../edit_module.py} | 6 +- .../sco_edit_ue.py => formations/edit_ue.py} | 23 +++---- .../formation_io.py} | 54 +++------------- .../formation_versions.py} | 8 +-- app/models/ues.py | 4 +- app/scodoc/sco_bulletins_json.py | 4 +- app/scodoc/sco_bulletins_xml.py | 4 +- app/scodoc/sco_formsemestre_edit.py | 6 +- app/scodoc/sco_formsemestre_status.py | 9 ++- app/scodoc/sco_placement.py | 4 +- app/scodoc/sco_tag_module.py | 4 +- app/scodoc/sco_ue_external.py | 14 ++-- app/views/notes.py | 64 +++++++++---------- app/views/notes_formsemestre.py | 9 ++- tests/scenarios/test_scenario1_formation.py | 7 +- tests/unit/sco_fake_gen.py | 18 +++--- tests/unit/test_formations.py | 51 +++++++-------- tests/unit/test_formsemestre.py | 9 ++- tests/unit/yaml_setup.py | 5 +- .../fakedatabase/create_test_api_database.py | 5 +- 23 files changed, 147 insertions(+), 202 deletions(-) rename app/{scodoc/sco_edit_formation.py => formations/edit_formation.py} (99%) rename app/{scodoc/sco_edit_matiere.py => formations/edit_matiere.py} (92%) rename app/{scodoc/sco_edit_module.py => formations/edit_module.py} (99%) rename app/{scodoc/sco_edit_ue.py => formations/edit_ue.py} (98%) rename app/{scodoc/sco_formations.py => formations/formation_io.py} (94%) rename app/{scodoc/sco_formation_versions.py => formations/formation_versions.py} (98%) diff --git a/app/api/formations.py b/app/api/formations.py index f675acc32..d2de7ce2e 100644 --- a/app/api/formations.py +++ b/app/api/formations.py @@ -30,7 +30,7 @@ from app.models import ( Module, UniteEns, ) -from app.scodoc import sco_formations +from app.formations import formation_io from app.scodoc.sco_permissions import Permission @@ -141,7 +141,7 @@ def formation_export_by_formation_id(formation_id: int, export_ids=False): formation = query.first_or_404(formation_id) app.set_sco_dept(formation.departement.acronym) try: - data = sco_formations.formation_export(formation_id, export_ids) + data = formation_io.formation_export(formation_id, export_ids) except ValueError: return json_error(500, message="Erreur inconnue") diff --git a/app/scodoc/sco_edit_formation.py b/app/formations/edit_formation.py similarity index 99% rename from app/scodoc/sco_edit_formation.py rename to app/formations/edit_formation.py index 6eb276035..3b9a26368 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/formations/edit_formation.py @@ -33,6 +33,7 @@ from flask import flash, g, url_for, render_template, request import sqlalchemy from app import db +from app.formations import edit_ue from app.models import SHORT_STR_LEN from app.models.formations import Formation from app.models.modules import Module @@ -45,7 +46,6 @@ from app.scodoc.sco_exceptions import ScoValueError, ScoNonEmptyFormationObject from app.scodoc import sco_cache from app.scodoc import codes_cursus -from app.scodoc import sco_edit_ue def formation_delete(formation_id=None, dialog_confirmed=False): @@ -123,7 +123,7 @@ def do_formation_delete(formation_id): db.session.flush() # Suppression des UEs for ue in formation.ues: - sco_edit_ue.do_ue_delete(ue, force=True) + edit_ue.do_ue_delete(ue, force=True) db.session.delete(formation) diff --git a/app/scodoc/sco_edit_matiere.py b/app/formations/edit_matiere.py similarity index 92% rename from app/scodoc/sco_edit_matiere.py rename to app/formations/edit_matiere.py index 9bba3d05c..26add3956 100644 --- a/app/scodoc/sco_edit_matiere.py +++ b/app/formations/edit_matiere.py @@ -61,7 +61,7 @@ def matiere_list(*args, **kw): def do_matiere_edit(*args, **kw): "edit a matiere" - from app.scodoc import sco_edit_ue + from app.formations import edit_ue cnx = ndb.GetDBConnexion() # check @@ -70,17 +70,17 @@ def do_matiere_edit(*args, **kw): raise ScoLockedFormError() # edit _matiereEditor.edit(cnx, *args, **kw) - formation_id = sco_edit_ue.ue_list({"ue_id": mat["ue_id"]})[0]["formation_id"] + formation_id = edit_ue.ue_list({"ue_id": mat["ue_id"]})[0]["formation_id"] db.session.get(Formation, formation_id).invalidate_cached_sems() def do_matiere_create(args): "create a matiere" - from app.scodoc import sco_edit_ue + from app.formations import edit_ue cnx = ndb.GetDBConnexion() # check - ue = sco_edit_ue.ue_list({"ue_id": args["ue_id"]})[0] + ue = edit_ue.ue_list({"ue_id": args["ue_id"]})[0] # create matiere r = _matiereEditor.create(cnx, args) @@ -180,23 +180,22 @@ def can_delete_matiere(matiere: Matiere) -> tuple[bool, str]: def do_matiere_delete(oid): "delete matiere and attached modules" - from app.scodoc import sco_edit_ue - from app.scodoc import sco_edit_module + from app.formations import edit_module, edit_ue cnx = ndb.GetDBConnexion() # check matiere = Matiere.query.get_or_404(oid) mat = matiere_list({"matiere_id": oid})[0] # compat sco7 - ue = sco_edit_ue.ue_list({"ue_id": mat["ue_id"]})[0] + ue = edit_ue.ue_list({"ue_id": mat["ue_id"]})[0] if not can_delete_matiere(matiere): # il y a au moins un modimpl dans un module de cette matière raise ScoNonEmptyFormationObject("Matière", matiere.titre) - log("do_matiere_delete: matiere_id=%s" % matiere.id) + log(f"do_matiere_delete: matiere_id={matiere.id}") # delete all modules in this matiere - mods = sco_edit_module.module_list({"matiere_id": matiere.id}) + mods = edit_module.module_list({"matiere_id": matiere.id}) for mod in mods: - sco_edit_module.do_module_delete(mod["module_id"]) + edit_module.do_module_delete(mod["module_id"]) _matiereEditor.delete(cnx, oid) # news @@ -211,7 +210,7 @@ def do_matiere_delete(oid): def matiere_delete(matiere_id=None): """Delete matière""" - from app.scodoc import sco_edit_ue + from app.formations import edit_ue matiere = Matiere.query.get_or_404(matiere_id) if not can_delete_matiere(matiere): @@ -228,15 +227,15 @@ def matiere_delete(matiere_id=None): ) mat = matiere_list(args={"matiere_id": matiere_id})[0] - UE = sco_edit_ue.ue_list(args={"ue_id": mat["ue_id"]})[0] + ue_dict = edit_ue.ue_list(args={"ue_id": mat["ue_id"]})[0] H = [ "

Suppression de la matière %(titre)s" % mat, - " dans l'UE (%(acronyme)s))

" % UE, + " dans l'UE (%(acronyme)s))" % ue_dict, ] dest_url = url_for( "notes.ue_table", scodoc_dept=g.scodoc_dept, - formation_id=str(UE["formation_id"]), + formation_id=str(ue_dict["formation_id"]), ) tf = TrivialFormulator( request.base_url, @@ -261,18 +260,18 @@ def matiere_delete(matiere_id=None): def matiere_edit(matiere_id=None): """Edit matiere""" - from app.scodoc import sco_edit_ue + from app.formations import edit_ue F = matiere_list(args={"matiere_id": matiere_id}) if not F: raise ScoValueError("Matière inexistante !") F = F[0] - ues = sco_edit_ue.ue_list(args={"ue_id": F["ue_id"]}) + ues = edit_ue.ue_list(args={"ue_id": F["ue_id"]}) if not ues: raise ScoValueError("UE inexistante !") ue = ues[0] formation: Formation = Formation.query.get_or_404(ue["formation_id"]) - ues = sco_edit_ue.ue_list(args={"formation_id": ue["formation_id"]}) + ues = 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 = [ diff --git a/app/scodoc/sco_edit_module.py b/app/formations/edit_module.py similarity index 99% rename from app/scodoc/sco_edit_module.py rename to app/formations/edit_module.py index 27b197e9f..8cb8dccf6 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/formations/edit_module.py @@ -35,6 +35,7 @@ from flask_login import current_user from app import db, log from app import models +from app.formations import edit_matiere from app.models import APO_CODE_STR_LEN from app.models import Formation, Matiere, Module, UniteEns from app.models import FormSemestre, ModuleImpl @@ -52,7 +53,6 @@ from app.scodoc.sco_exceptions import ( ScoNonEmptyFormationObject, ) from app.scodoc import codes_cursus -from app.scodoc import sco_edit_matiere from app.scodoc import sco_moduleimpl _moduleEditor = ndb.EditableTable( @@ -833,7 +833,7 @@ def module_edit( if matiere: tf[2]["matiere_id"] = matiere.id else: - matiere_id = sco_edit_matiere.do_matiere_create( + matiere_id = edit_matiere.do_matiere_create( {"ue_id": ue.id, "titre": ue.titre or "", "numero": 1}, ) tf[2]["matiere_id"] = matiere_id @@ -899,8 +899,6 @@ def module_table(formation_id): """Liste des modules de la formation (XXX inutile ou a revoir) """ - from app.scodoc import sco_formations - if not formation_id: raise ScoValueError("invalid formation !") formation: Formation = Formation.query.get_or_404(formation_id) diff --git a/app/scodoc/sco_edit_ue.py b/app/formations/edit_ue.py similarity index 98% rename from app/scodoc/sco_edit_ue.py rename to app/formations/edit_ue.py index c47cca531..3e4d13641 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/formations/edit_ue.py @@ -37,6 +37,7 @@ from flask_login import current_user from app import db, log from app.but import apc_edit_ue +from app.formations import edit_matiere, edit_module from app.models import APO_CODE_STR_LEN, SHORT_STR_LEN from app.models import ( Formation, @@ -63,8 +64,6 @@ from app.scodoc.sco_exceptions import ( from app.scodoc import codes_cursus from app.scodoc import sco_edit_apc -from app.scodoc import sco_edit_matiere -from app.scodoc import sco_edit_module from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_tag_module @@ -548,12 +547,12 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No if is_apc or cursus.UE_IS_MODULE or tf[2]["create_matiere"]: # rappel: en APC, toutes les UE ont une matière, créée ici # (inutilisée mais à laquelle les modules sont rattachés) - matiere_id = sco_edit_matiere.do_matiere_create( + matiere_id = edit_matiere.do_matiere_create( {"ue_id": ue_id, "titre": tf[2]["titre"], "numero": 1}, ) if cursus.UE_IS_MODULE: # dans ce mode, crée un (unique) module dans l'UE: - _ = sco_edit_module.do_module_create( + _ = edit_module.do_module_create( { "titre": tf[2]["titre"], "code": tf[2]["acronyme"], @@ -608,7 +607,7 @@ def _add_ue_semestre_id(ues: list[dict], is_apc): ue["semestre_id"] = codes_cursus.UE_SEM_DEFAULT else: # était le comportement ScoDoc7 - modules = sco_edit_module.module_list(args={"ue_id": ue["ue_id"]}) + modules = edit_module.module_list(args={"ue_id": ue["ue_id"]}) if modules: ue["semestre_id"] = modules[0]["semestre_id"] else: @@ -1254,11 +1253,11 @@ def _ue_table_matieres( H = [] if not parcours.UE_IS_MODULE: H.append('