forked from ScoDoc/ScoDoc
Améliore import/export formations BUT: identification des niveaux si libellés dupliqués. + Fix unicité apprentissages critiques-modules.
This commit is contained in:
parent
45ec03ec11
commit
f0f9158ac6
@ -604,6 +604,7 @@ app_critiques_modules = db.Table(
|
||||
db.ForeignKey("apc_app_critique.id", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
),
|
||||
db.UniqueConstraint("module_id", "app_crit_id", name="uix_module_id_app_crit_id"),
|
||||
)
|
||||
|
||||
|
||||
|
@ -47,7 +47,6 @@ from app.scodoc import html_sco_header
|
||||
from app.scodoc import sco_cache
|
||||
from app.scodoc import codes_cursus
|
||||
from app.scodoc import sco_edit_ue
|
||||
from app.scodoc import sco_formsemestre
|
||||
|
||||
|
||||
def formation_delete(formation_id=None, dialog_confirmed=False):
|
||||
|
@ -125,6 +125,9 @@ def formation_export_dict(
|
||||
if formation.is_apc():
|
||||
# BUT: indique niveau de compétence associé à l'UE
|
||||
if ue.niveau_competence:
|
||||
ue_dict["apc_niveau_competence_titre"] = (
|
||||
ue.niveau_competence.competence.titre
|
||||
)
|
||||
ue_dict["apc_niveau_libelle"] = ue.niveau_competence.libelle
|
||||
ue_dict["apc_niveau_annee"] = ue.niveau_competence.annee
|
||||
ue_dict["apc_niveau_ordre"] = ue.niveau_competence.ordre
|
||||
@ -219,7 +222,7 @@ def formation_export(
|
||||
"""Get a formation, with UE, matieres, modules
|
||||
in desired format
|
||||
"""
|
||||
formation: Formation = Formation.query.get_or_404(formation_id)
|
||||
formation = Formation.get_formation(formation_id)
|
||||
f_dict = formation_export_dict(
|
||||
formation,
|
||||
export_ids=export_ids,
|
||||
@ -258,29 +261,39 @@ def _formation_retreive_refcomp(f_dict: dict) -> int:
|
||||
return refcomp.id
|
||||
else:
|
||||
flash(
|
||||
f"Impossible de trouver le référentiel de compétence pour {refcomp_specialite} : est-il chargé ?"
|
||||
f"""Impossible de trouver le référentiel de compétence pour {
|
||||
refcomp_specialite} : est-il chargé ?"""
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def _formation_retreive_apc_niveau(
|
||||
referentiel_competence_id: int, ue_dict: dict
|
||||
) -> int:
|
||||
) -> int | None:
|
||||
"""Recherche dans le ref. de comp. un niveau pour cette UE.
|
||||
Utilise (libelle, annee, ordre) comme clé.
|
||||
Utilise (libelle, annee, ordre) comme clé, ou
|
||||
(competence_titre, libelle, annee, ordre) si présent.
|
||||
"""
|
||||
libelle = ue_dict.get("apc_niveau_libelle")
|
||||
annee = ue_dict.get("apc_niveau_annee")
|
||||
ordre = ue_dict.get("apc_niveau_ordre")
|
||||
if all((libelle, annee, ordre)):
|
||||
competence_titre = ue_dict.get("apc_niveau_competence_titre")
|
||||
niveau = None
|
||||
if all((competence_titre, libelle, annee, ordre)):
|
||||
niveau = (
|
||||
ApcNiveau.query.filter_by(libelle=libelle, annee=annee, ordre=ordre)
|
||||
.join(ApcCompetence)
|
||||
.filter_by(referentiel_id=referentiel_competence_id, titre=competence_titre)
|
||||
).first()
|
||||
|
||||
elif all((libelle, annee, ordre)):
|
||||
niveau = (
|
||||
ApcNiveau.query.filter_by(libelle=libelle, annee=annee, ordre=ordre)
|
||||
.join(ApcCompetence)
|
||||
.filter_by(referentiel_id=referentiel_competence_id)
|
||||
).first()
|
||||
if niveau is not None:
|
||||
return niveau.id
|
||||
return None
|
||||
|
||||
return niveau.id if niveau is not None else None
|
||||
|
||||
|
||||
def formation_import_xml(doc: str, import_tags=True, use_local_refcomp=False):
|
||||
|
43
migrations/versions/f6cb3d4e44ec_fix_refcomp_geii.py
Normal file
43
migrations/versions/f6cb3d4e44ec_fix_refcomp_geii.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""fix_refcomp_geii
|
||||
|
||||
Revision ID: f6cb3d4e44ec
|
||||
Revises: 9794534db935
|
||||
Create Date: 2024-07-10 17:03:58.549168
|
||||
|
||||
Élimine éventuels doublons dans associations Apprentissages critiques du ref. comp.
|
||||
Pour le cas de GEII seulement.
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "f6cb3d4e44ec"
|
||||
down_revision = "9794534db935"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TABLE apc_modules_acs_temp AS
|
||||
SELECT DISTINCT module_id, app_crit_id
|
||||
FROM apc_modules_acs;
|
||||
DELETE FROM apc_modules_acs;
|
||||
INSERT INTO apc_modules_acs (module_id, app_crit_id)
|
||||
SELECT module_id, app_crit_id
|
||||
FROM apc_modules_acs_temp;
|
||||
"""
|
||||
)
|
||||
with op.batch_alter_table("apc_modules_acs", schema=None) as batch_op:
|
||||
batch_op.create_unique_constraint(
|
||||
"uix_module_id_app_crit_id", ["module_id", "app_crit_id"]
|
||||
)
|
||||
|
||||
op.drop_table("apc_modules_acs_temp")
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("apc_modules_acs", schema=None) as batch_op:
|
||||
batch_op.drop_constraint("uix_module_id_app_crit_id", type_="unique")
|
Loading…
Reference in New Issue
Block a user