2021-12-03 14:13:49 +01:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2021-12-03 14:13:49 +01:00
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
2021-12-02 12:08:03 +01:00
|
|
|
"""ScoDoc 9 models : Référentiel Compétence BUT 2021
|
|
|
|
"""
|
2021-12-03 11:03:33 +01:00
|
|
|
from datetime import datetime
|
2023-04-10 11:25:46 +02:00
|
|
|
import functools
|
2023-04-03 17:46:31 +02:00
|
|
|
from operator import attrgetter
|
2024-04-05 23:41:34 +02:00
|
|
|
import yaml
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2023-06-21 13:09:04 +02:00
|
|
|
from flask import g
|
2023-04-03 17:40:45 +02:00
|
|
|
from flask_sqlalchemy.query import Query
|
2022-01-03 12:25:42 +01:00
|
|
|
from sqlalchemy.orm import class_mapper
|
|
|
|
import sqlalchemy
|
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
from app import db, log, models
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
from app.scodoc.sco_utils import ModuleType
|
2024-04-05 23:41:34 +02:00
|
|
|
from app.scodoc.sco_exceptions import ScoNoReferentielCompetences, ScoValueError
|
|
|
|
|
|
|
|
REFCOMP_EQUIVALENCE_FILENAME = "ressources/referentiels/equivalences.yaml"
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
|
2022-01-03 12:25:42 +01:00
|
|
|
# from https://stackoverflow.com/questions/2537471/method-of-iterating-over-sqlalchemy-models-defined-columns
|
|
|
|
def attribute_names(cls):
|
|
|
|
"liste ids (noms de colonnes) d'un modèle"
|
|
|
|
return [
|
|
|
|
prop.key
|
|
|
|
for prop in class_mapper(cls).iterate_properties
|
|
|
|
if isinstance(prop, sqlalchemy.orm.ColumnProperty)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
class XMLModel:
|
2022-04-26 06:02:17 +02:00
|
|
|
"""Mixin class, to ease loading Orebut XMLs"""
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
_xml_attribs = {} # to be overloaded
|
|
|
|
id = "_"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def attr_from_xml(cls, args: dict) -> dict:
|
|
|
|
"""dict with attributes imported from Orébut XML
|
|
|
|
and renamed for our models.
|
|
|
|
The mapping is specified by the _xml_attribs
|
|
|
|
attribute in each model class.
|
2022-01-03 12:25:42 +01:00
|
|
|
Keep only attributes corresponding to columns in our model:
|
|
|
|
other XML attributes are simply ignored.
|
2021-12-02 12:08:03 +01:00
|
|
|
"""
|
2022-01-03 12:25:42 +01:00
|
|
|
columns = attribute_names(cls)
|
|
|
|
renamed_attributes = {cls._xml_attribs.get(k, k): v for (k, v) in args.items()}
|
|
|
|
return {k: renamed_attributes[k] for k in renamed_attributes if k in columns}
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f'<{self.__class__.__name__} {self.id} "{self.titre if hasattr(self, "titre") else ""}">'
|
|
|
|
|
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcReferentielCompetences(models.ScoDocModel, XMLModel):
|
2022-01-05 23:42:11 +01:00
|
|
|
"Référentiel de compétence d'une spécialité"
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-02-09 11:56:20 +01:00
|
|
|
dept_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("departement.id", ondelete="CASCADE"), index=True
|
|
|
|
)
|
2023-01-03 13:36:55 +01:00
|
|
|
annexe = db.Column(db.Text()) # '1', '22', ...
|
|
|
|
specialite = db.Column(db.Text()) # 'CJ', 'RT', 'INFO', ...
|
|
|
|
specialite_long = db.Column(
|
|
|
|
db.Text()
|
|
|
|
) # 'Carrière Juridique', 'Réseaux et télécommunications', ...
|
|
|
|
type_titre = db.Column(db.Text()) # 'B.U.T.'
|
|
|
|
type_structure = db.Column(db.Text()) # 'type1', 'type2', ...
|
2022-01-03 12:25:42 +01:00
|
|
|
type_departement = db.Column(db.Text()) # "secondaire", "tertiaire"
|
2023-01-03 13:36:55 +01:00
|
|
|
version_orebut = db.Column(db.Text()) # '2021-12-11 00:00:00'
|
2021-12-03 11:03:33 +01:00
|
|
|
_xml_attribs = { # Orébut xml attrib : attribute
|
2021-12-02 12:08:03 +01:00
|
|
|
"type": "type_titre",
|
2022-01-03 12:25:42 +01:00
|
|
|
"version": "version_orebut",
|
2021-12-02 12:08:03 +01:00
|
|
|
}
|
2021-12-03 11:03:33 +01:00
|
|
|
# ScoDoc specific fields:
|
|
|
|
scodoc_date_loaded = db.Column(db.DateTime, default=datetime.utcnow)
|
|
|
|
scodoc_orig_filename = db.Column(db.Text())
|
|
|
|
# Relations:
|
2021-12-02 12:08:03 +01:00
|
|
|
competences = db.relationship(
|
|
|
|
"ApcCompetence",
|
|
|
|
backref="referentiel",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
|
|
|
parcours = db.relationship(
|
|
|
|
"ApcParcours",
|
|
|
|
backref="referentiel",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
2023-04-06 16:10:32 +02:00
|
|
|
order_by="ApcParcours.numero, ApcParcours.code",
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
2023-03-26 10:08:50 +02:00
|
|
|
formations = db.relationship(
|
|
|
|
"Formation",
|
|
|
|
backref="referentiel_competence",
|
|
|
|
order_by="Formation.acronyme, Formation.version",
|
|
|
|
)
|
2023-06-30 09:34:29 +02:00
|
|
|
validations_annee = db.relationship(
|
|
|
|
"ApcValidationAnnee",
|
|
|
|
backref="referentiel_competence",
|
2023-10-25 23:07:34 +02:00
|
|
|
cascade="all, delete-orphan", # cascade at ORM level
|
2023-06-30 09:34:29 +02:00
|
|
|
lazy="dynamic",
|
|
|
|
)
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-02-12 20:25:22 +01:00
|
|
|
def __repr__(self):
|
2022-07-10 12:08:22 +02:00
|
|
|
return f"<ApcReferentielCompetences {self.id} {self.specialite!r} {self.departement!r}>"
|
2022-02-12 20:25:22 +01:00
|
|
|
|
2024-04-05 23:41:34 +02:00
|
|
|
def get_title(self) -> str:
|
|
|
|
"Titre affichable"
|
|
|
|
# utilise type_titre (B.U.T.), spécialité, version
|
|
|
|
return f"{self.type_titre} {self.specialite} {self.get_version()}"
|
|
|
|
|
2022-12-02 17:41:19 +01:00
|
|
|
def get_version(self) -> str:
|
|
|
|
"La version, normalement sous forme de date iso yyy-mm-dd"
|
|
|
|
if not self.version_orebut:
|
|
|
|
return ""
|
|
|
|
return self.version_orebut.split()[0]
|
|
|
|
|
2023-01-17 01:05:48 +01:00
|
|
|
def to_dict(self, parcours: list["ApcParcours"] = None, with_app_critiques=True):
|
2021-12-02 12:08:03 +01:00
|
|
|
"""Représentation complète du ref. de comp.
|
|
|
|
comme un dict.
|
2023-01-17 01:05:48 +01:00
|
|
|
Si parcours est une liste de parcours, restreint l'export aux parcours listés.
|
2021-12-02 12:08:03 +01:00
|
|
|
"""
|
2021-12-02 17:36:32 +01:00
|
|
|
return {
|
|
|
|
"dept_id": self.dept_id,
|
2022-01-03 12:25:42 +01:00
|
|
|
"annexe": self.annexe,
|
2021-12-02 17:36:32 +01:00
|
|
|
"specialite": self.specialite,
|
|
|
|
"specialite_long": self.specialite_long,
|
2022-01-03 12:25:42 +01:00
|
|
|
"type_structure": self.type_structure,
|
|
|
|
"type_departement": self.type_departement,
|
2021-12-02 17:36:32 +01:00
|
|
|
"type_titre": self.type_titre,
|
2022-01-03 12:25:42 +01:00
|
|
|
"version_orebut": self.version_orebut,
|
2024-04-05 23:41:34 +02:00
|
|
|
"scodoc_date_loaded": (
|
|
|
|
self.scodoc_date_loaded.isoformat() + "Z"
|
|
|
|
if self.scodoc_date_loaded
|
|
|
|
else ""
|
|
|
|
),
|
2021-12-03 11:03:33 +01:00
|
|
|
"scodoc_orig_filename": self.scodoc_orig_filename,
|
2023-01-17 01:05:48 +01:00
|
|
|
"competences": {
|
|
|
|
x.titre: x.to_dict(with_app_critiques=with_app_critiques)
|
|
|
|
for x in self.competences
|
|
|
|
},
|
|
|
|
"parcours": {
|
|
|
|
x.code: x.to_dict()
|
|
|
|
for x in (self.parcours if parcours is None else parcours)
|
|
|
|
},
|
2021-12-02 17:36:32 +01:00
|
|
|
}
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-10-30 16:07:06 +01:00
|
|
|
def get_niveaux_by_parcours(
|
2023-04-03 17:46:31 +02:00
|
|
|
self, annee: int, parcours: list["ApcParcours"] = None
|
2022-10-30 16:07:06 +01:00
|
|
|
) -> tuple[list["ApcParcours"], dict]:
|
2022-04-29 08:17:04 +02:00
|
|
|
"""
|
|
|
|
Construit la liste des niveaux de compétences pour chaque parcours
|
2023-04-03 17:46:31 +02:00
|
|
|
de ce référentiel, ou seulement pour les parcours donnés.
|
2022-10-30 16:07:06 +01:00
|
|
|
|
2022-04-29 08:17:04 +02:00
|
|
|
Les niveaux sont groupés par parcours, en isolant les niveaux de tronc commun.
|
2022-10-30 16:07:06 +01:00
|
|
|
|
2022-04-29 08:17:04 +02:00
|
|
|
Le tronc commun n'est pas identifié comme tel dans les référentiels Orébut:
|
|
|
|
on cherche les niveaux qui sont présents dans tous les parcours et les range sous
|
|
|
|
la clé "TC" (toujours présente mais éventuellement liste vide si pas de tronc commun).
|
|
|
|
|
2022-12-08 13:59:23 +01:00
|
|
|
Résultat: couple
|
|
|
|
( [ ApcParcours ],
|
|
|
|
{
|
|
|
|
"TC" : [ ApcNiveau ],
|
|
|
|
parcour.id : [ ApcNiveau ]
|
|
|
|
}
|
|
|
|
)
|
2022-04-29 08:17:04 +02:00
|
|
|
"""
|
2022-10-30 16:07:06 +01:00
|
|
|
parcours_ref = self.parcours.order_by(ApcParcours.numero).all()
|
2023-04-03 17:46:31 +02:00
|
|
|
if parcours is None:
|
2022-10-30 16:07:06 +01:00
|
|
|
parcours = parcours_ref
|
2022-04-29 08:17:04 +02:00
|
|
|
niveaux_by_parcours = {
|
2022-06-25 23:42:39 +02:00
|
|
|
parcour.id: ApcNiveau.niveaux_annee_de_parcours(parcour, annee, self)
|
2022-10-30 16:07:06 +01:00
|
|
|
for parcour in parcours_ref
|
2022-04-29 08:17:04 +02:00
|
|
|
}
|
|
|
|
# Cherche tronc commun
|
2022-08-04 16:54:59 +02:00
|
|
|
if niveaux_by_parcours:
|
|
|
|
niveaux_ids_tc = set.intersection(
|
|
|
|
*[
|
|
|
|
{n.id for n in niveaux_by_parcours[parcour_id]}
|
|
|
|
for parcour_id in niveaux_by_parcours
|
|
|
|
]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
niveaux_ids_tc = set()
|
2022-04-29 08:17:04 +02:00
|
|
|
# Enleve les niveaux du tronc commun
|
|
|
|
niveaux_by_parcours_no_tc = {
|
|
|
|
parcour.id: [
|
|
|
|
niveau
|
|
|
|
for niveau in niveaux_by_parcours[parcour.id]
|
|
|
|
if niveau.id not in niveaux_ids_tc
|
|
|
|
]
|
|
|
|
for parcour in parcours
|
|
|
|
}
|
|
|
|
# Niveaux du TC
|
|
|
|
niveaux_tc = []
|
|
|
|
if len(parcours):
|
|
|
|
niveaux_parcours_1 = niveaux_by_parcours[parcours[0].id]
|
|
|
|
niveaux_tc = [
|
|
|
|
niveau for niveau in niveaux_parcours_1 if niveau.id in niveaux_ids_tc
|
|
|
|
]
|
|
|
|
niveaux_by_parcours_no_tc["TC"] = niveaux_tc
|
2022-10-30 16:07:06 +01:00
|
|
|
return parcours, niveaux_by_parcours_no_tc
|
2022-04-29 08:17:04 +02:00
|
|
|
|
2023-01-17 01:05:48 +01:00
|
|
|
def get_competences_tronc_commun(self) -> list["ApcCompetence"]:
|
|
|
|
"""Liste des compétences communes à tous les parcours du référentiel."""
|
|
|
|
parcours = self.parcours.all()
|
|
|
|
if not parcours:
|
|
|
|
return []
|
|
|
|
|
|
|
|
ids = set.intersection(
|
|
|
|
*[
|
|
|
|
{competence.id for competence in parcour.query_competences()}
|
|
|
|
for parcour in parcours
|
|
|
|
]
|
|
|
|
)
|
|
|
|
return sorted(
|
|
|
|
[
|
|
|
|
competence
|
|
|
|
for competence in parcours[0].query_competences()
|
|
|
|
if competence.id in ids
|
|
|
|
],
|
2023-04-03 17:46:31 +02:00
|
|
|
key=attrgetter("numero"),
|
2023-01-17 01:05:48 +01:00
|
|
|
)
|
|
|
|
|
2023-03-28 21:59:09 +02:00
|
|
|
def table_niveaux_parcours(self) -> dict:
|
|
|
|
"""Une table avec les parcours:années BUT et les niveaux
|
|
|
|
{ parcour_id : { 1 : { competence_id : ordre }}}
|
|
|
|
"""
|
|
|
|
parcours_info = {}
|
|
|
|
for parcour in self.parcours:
|
|
|
|
descr_parcour = {}
|
|
|
|
parcours_info[parcour.id] = descr_parcour
|
|
|
|
for annee in (1, 2, 3):
|
|
|
|
descr_parcour[annee] = {
|
|
|
|
niveau.competence.id: niveau.ordre
|
|
|
|
for niveau in ApcNiveau.niveaux_annee_de_parcours(
|
|
|
|
parcour, annee, self
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return parcours_info
|
|
|
|
|
2024-04-05 23:41:34 +02:00
|
|
|
def equivalents(self) -> set["ApcReferentielCompetences"]:
|
|
|
|
"""Ensemble des référentiels du même département
|
|
|
|
qui peuvent être considérés comme "équivalents", au sens
|
|
|
|
une formation de ce référentiel pourrait changer vers un équivalent,
|
|
|
|
en ignorant les apprentissages critiques.
|
|
|
|
Pour cela, il faut avoir le même type, etc et les mêmes compétences,
|
|
|
|
niveaux et parcours (voir map_to_other_referentiel).
|
|
|
|
"""
|
|
|
|
candidats = ApcReferentielCompetences.query.filter_by(
|
|
|
|
dept_id=self.dept_id
|
|
|
|
).filter(ApcReferentielCompetences.id != self.id)
|
|
|
|
return {
|
|
|
|
referentiel
|
|
|
|
for referentiel in candidats
|
|
|
|
if not isinstance(self.map_to_other_referentiel(referentiel), str)
|
|
|
|
}
|
|
|
|
|
|
|
|
def map_to_other_referentiel(
|
|
|
|
self, other: "ApcReferentielCompetences"
|
|
|
|
) -> str | tuple[dict[int, int], dict[int, int], dict[int, int]]:
|
|
|
|
"""Build mapping between this referentiel and ref2.
|
|
|
|
If successful, returns 3 dicts mapping self ids to other ids.
|
|
|
|
Else return a string, error message.
|
|
|
|
"""
|
|
|
|
if self.type_structure != other.type_structure:
|
|
|
|
return "type_structure mismatch"
|
|
|
|
if self.type_departement != other.type_departement:
|
|
|
|
return "type_departement mismatch"
|
|
|
|
# Table d'équivalences entre refs:
|
|
|
|
equiv = self._load_config_equivalences()
|
2024-06-02 12:05:01 +02:00
|
|
|
# Même specialité (ou alias) ?
|
|
|
|
if self.specialite != other.specialite and other.specialite not in equiv.get(
|
|
|
|
"alias", []
|
|
|
|
):
|
|
|
|
return "specialite mismatch"
|
2024-04-05 23:41:34 +02:00
|
|
|
# mêmes parcours ?
|
|
|
|
eq_parcours = equiv.get("parcours", {})
|
|
|
|
parcours_by_code_1 = {eq_parcours.get(p.code, p.code): p for p in self.parcours}
|
|
|
|
parcours_by_code_2 = {
|
|
|
|
eq_parcours.get(p.code, p.code): p for p in other.parcours
|
|
|
|
}
|
|
|
|
if parcours_by_code_1.keys() != parcours_by_code_2.keys():
|
|
|
|
return "parcours mismatch"
|
|
|
|
parcours_map = {
|
|
|
|
parcours_by_code_1[eq_parcours.get(code, code)]
|
|
|
|
.id: parcours_by_code_2[eq_parcours.get(code, code)]
|
|
|
|
.id
|
|
|
|
for code in parcours_by_code_1
|
|
|
|
}
|
|
|
|
# mêmes compétences ?
|
|
|
|
competence_by_code_1 = {c.titre: c for c in self.competences}
|
|
|
|
competence_by_code_2 = {c.titre: c for c in other.competences}
|
|
|
|
if competence_by_code_1.keys() != competence_by_code_2.keys():
|
|
|
|
return "competences mismatch"
|
|
|
|
competences_map = {
|
|
|
|
competence_by_code_1[titre].id: competence_by_code_2[titre].id
|
|
|
|
for titre in competence_by_code_1
|
|
|
|
}
|
|
|
|
# mêmes niveaux (dans chaque compétence) ?
|
|
|
|
niveaux_map = {}
|
|
|
|
for titre in competence_by_code_1:
|
|
|
|
c1 = competence_by_code_1[titre]
|
|
|
|
c2 = competence_by_code_2[titre]
|
|
|
|
niveau_by_attr_1 = {(n.annee, n.ordre, n.libelle): n for n in c1.niveaux}
|
|
|
|
niveau_by_attr_2 = {(n.annee, n.ordre, n.libelle): n for n in c2.niveaux}
|
|
|
|
if niveau_by_attr_1.keys() != niveau_by_attr_2.keys():
|
|
|
|
return f"niveaux mismatch in comp. '{titre}'"
|
|
|
|
niveaux_map.update(
|
|
|
|
{
|
|
|
|
niveau_by_attr_1[a].id: niveau_by_attr_2[a].id
|
|
|
|
for a in niveau_by_attr_1
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return parcours_map, competences_map, niveaux_map
|
|
|
|
|
|
|
|
def _load_config_equivalences(self) -> dict:
|
|
|
|
"""Load config file ressources/referentiels/equivalences.yaml
|
|
|
|
used to define equivalences between distinct referentiels
|
2024-06-02 12:05:01 +02:00
|
|
|
return a dict, with optional keys:
|
|
|
|
alias: list of equivalent names for speciality (eg SD == STID)
|
|
|
|
parcours: dict with equivalent parcours acronyms
|
2024-04-05 23:41:34 +02:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
with open(REFCOMP_EQUIVALENCE_FILENAME, encoding="utf-8") as f:
|
|
|
|
doc = yaml.safe_load(f.read())
|
|
|
|
except FileNotFoundError:
|
|
|
|
log(f"_load_config_equivalences: {REFCOMP_EQUIVALENCE_FILENAME} not found")
|
|
|
|
return {}
|
|
|
|
except yaml.parser.ParserError as exc:
|
|
|
|
raise ScoValueError(
|
|
|
|
f"erreur dans le fichier {REFCOMP_EQUIVALENCE_FILENAME}"
|
|
|
|
) from exc
|
|
|
|
return doc.get(self.specialite, {})
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcCompetence(models.ScoDocModel, XMLModel):
|
2022-01-05 23:42:11 +01:00
|
|
|
"Compétence"
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
referentiel_id = db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_referentiel_competences.id", ondelete="CASCADE"),
|
|
|
|
nullable=False,
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
2022-01-05 23:42:11 +01:00
|
|
|
# les compétences dans Orébut sont identifiées par leur id unique
|
2022-02-12 20:25:22 +01:00
|
|
|
# (mais id_orebut n'est pas unique car le même ref. pourra être chargé dans plusieurs depts)
|
|
|
|
id_orebut = db.Column(db.Text(), nullable=True, index=True)
|
2021-12-03 11:03:33 +01:00
|
|
|
titre = db.Column(db.Text(), nullable=False, index=True)
|
2021-12-02 12:08:03 +01:00
|
|
|
titre_long = db.Column(db.Text())
|
|
|
|
couleur = db.Column(db.Text())
|
2023-04-03 17:46:31 +02:00
|
|
|
numero = db.Column(db.Integer, nullable=False, default=0) # ordre de présentation
|
2021-12-02 12:08:03 +01:00
|
|
|
_xml_attribs = { # xml_attrib : attribute
|
2022-01-03 12:25:42 +01:00
|
|
|
"id": "id_orebut",
|
|
|
|
"nom_court": "titre", # was name
|
2021-12-02 12:08:03 +01:00
|
|
|
"libelle_long": "titre_long",
|
|
|
|
}
|
|
|
|
situations = db.relationship(
|
|
|
|
"ApcSituationPro",
|
|
|
|
backref="competence",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
|
|
|
composantes_essentielles = db.relationship(
|
|
|
|
"ApcComposanteEssentielle",
|
|
|
|
backref="competence",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
|
|
|
niveaux = db.relationship(
|
|
|
|
"ApcNiveau",
|
|
|
|
backref="competence",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
|
|
|
|
2022-02-12 20:25:22 +01:00
|
|
|
def __repr__(self):
|
2022-05-22 03:26:39 +02:00
|
|
|
return f"<ApcCompetence {self.id} {self.titre!r}>"
|
2022-02-12 20:25:22 +01:00
|
|
|
|
2023-01-17 01:05:48 +01:00
|
|
|
def to_dict(self, with_app_critiques=True):
|
2022-06-29 19:25:08 +02:00
|
|
|
"repr dict recursive sur situations, composantes, niveaux"
|
2021-12-02 17:36:32 +01:00
|
|
|
return {
|
2022-01-03 12:25:42 +01:00
|
|
|
"id_orebut": self.id_orebut,
|
2021-12-02 17:36:32 +01:00
|
|
|
"titre": self.titre,
|
|
|
|
"titre_long": self.titre_long,
|
|
|
|
"couleur": self.couleur,
|
|
|
|
"numero": self.numero,
|
|
|
|
"situations": [x.to_dict() for x in self.situations],
|
|
|
|
"composantes_essentielles": [
|
|
|
|
x.to_dict() for x in self.composantes_essentielles
|
|
|
|
],
|
2023-01-17 01:05:48 +01:00
|
|
|
"niveaux": {
|
|
|
|
x.annee: x.to_dict(with_app_critiques=with_app_critiques)
|
|
|
|
for x in self.niveaux
|
|
|
|
},
|
2021-12-02 17:36:32 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:25:08 +02:00
|
|
|
def to_dict_bul(self) -> dict:
|
|
|
|
"dict court pour bulletins"
|
|
|
|
return {
|
|
|
|
"id_orebut": self.id_orebut,
|
|
|
|
"titre": self.titre,
|
|
|
|
"titre_long": self.titre_long,
|
|
|
|
"couleur": self.couleur,
|
|
|
|
"numero": self.numero,
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcSituationPro(models.ScoDocModel, XMLModel):
|
2022-04-26 06:02:17 +02:00
|
|
|
"Situation professionnelle"
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
competence_id = db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_competence.id", ondelete="CASCADE"),
|
|
|
|
nullable=False,
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
|
|
|
libelle = db.Column(db.Text(), nullable=False)
|
2023-04-03 17:40:45 +02:00
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
# aucun attribut (le text devient le libellé)
|
2021-12-02 17:36:32 +01:00
|
|
|
def to_dict(self):
|
|
|
|
return {"libelle": self.libelle}
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcComposanteEssentielle(models.ScoDocModel, XMLModel):
|
2022-04-26 06:02:17 +02:00
|
|
|
"Composante essentielle"
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
competence_id = db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_competence.id", ondelete="CASCADE"),
|
|
|
|
nullable=False,
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
|
|
|
libelle = db.Column(db.Text(), nullable=False)
|
|
|
|
|
2021-12-02 17:36:32 +01:00
|
|
|
def to_dict(self):
|
|
|
|
return {"libelle": self.libelle}
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcNiveau(models.ScoDocModel, XMLModel):
|
2022-04-29 08:17:04 +02:00
|
|
|
"""Niveau de compétence
|
|
|
|
Chaque niveau peut être associé à deux UE,
|
|
|
|
des semestres impair et pair de la même année.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "apc_niveau"
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
competence_id = db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_competence.id", ondelete="CASCADE"),
|
|
|
|
nullable=False,
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
|
|
|
libelle = db.Column(db.Text(), nullable=False)
|
2022-04-29 08:17:04 +02:00
|
|
|
annee = db.Column(db.Text(), nullable=False) # "BUT1", "BUT2", "BUT3"
|
|
|
|
# L'ordre est le niveau (1,2,3) ou (1,2) suivant la competence
|
2021-12-02 12:08:03 +01:00
|
|
|
ordre = db.Column(db.Integer, nullable=False) # 1, 2, 3
|
|
|
|
app_critiques = db.relationship(
|
|
|
|
"ApcAppCritique",
|
|
|
|
backref="niveau",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
2022-04-29 08:17:04 +02:00
|
|
|
ues = db.relationship("UniteEns", back_populates="niveau_competence")
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-04-26 06:02:17 +02:00
|
|
|
def __repr__(self):
|
2022-07-09 12:55:23 +02:00
|
|
|
return f"""<{self.__class__.__name__} {self.id} ordre={self.ordre!r} annee={
|
2022-05-22 03:26:39 +02:00
|
|
|
self.annee!r} {self.competence!r}>"""
|
2022-04-26 06:02:17 +02:00
|
|
|
|
2023-07-02 16:02:09 +02:00
|
|
|
def __str__(self):
|
|
|
|
return f"""{self.competence.titre} niveau {self.ordre}"""
|
|
|
|
|
2023-01-17 01:05:48 +01:00
|
|
|
def to_dict(self, with_app_critiques=True):
|
|
|
|
"as a dict, recursif (ou non) sur les AC"
|
2021-12-02 17:36:32 +01:00
|
|
|
return {
|
|
|
|
"libelle": self.libelle,
|
|
|
|
"annee": self.annee,
|
|
|
|
"ordre": self.ordre,
|
2024-04-05 23:41:34 +02:00
|
|
|
"app_critiques": (
|
|
|
|
{x.code: x.to_dict() for x in self.app_critiques}
|
|
|
|
if with_app_critiques
|
|
|
|
else {}
|
|
|
|
),
|
2021-12-02 17:36:32 +01:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:25:08 +02:00
|
|
|
def to_dict_bul(self):
|
|
|
|
"dict pour bulletins: indique la compétence, pas les ACs (pour l'instant ?)"
|
|
|
|
return {
|
|
|
|
"libelle": self.libelle,
|
|
|
|
"annee": self.annee,
|
|
|
|
"ordre": self.ordre,
|
|
|
|
"competence": self.competence.to_dict_bul(),
|
|
|
|
}
|
|
|
|
|
2023-04-10 11:25:46 +02:00
|
|
|
@functools.cached_property
|
|
|
|
def parcours(self) -> list["ApcParcours"]:
|
|
|
|
"""Les parcours passant par ce niveau.
|
|
|
|
Les associations Parcours/Niveaux/compétences ne sont jamais
|
|
|
|
changées par ScoDoc, la valeur est donc cachée.
|
|
|
|
"""
|
|
|
|
annee = int(self.annee[-1])
|
|
|
|
return (
|
|
|
|
ApcParcours.query.join(ApcAnneeParcours)
|
|
|
|
.filter_by(ordre=annee)
|
2023-07-10 13:58:16 +02:00
|
|
|
.join(ApcParcoursNiveauCompetence)
|
|
|
|
.join(ApcCompetence)
|
|
|
|
.join(ApcNiveau)
|
2023-04-10 11:25:46 +02:00
|
|
|
.filter_by(id=self.id)
|
|
|
|
.order_by(ApcParcours.numero, ApcParcours.code)
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
|
|
|
|
@functools.cached_property
|
|
|
|
def is_tronc_commun(self) -> bool:
|
|
|
|
"""Vrai si ce niveau fait partie du Tronc Commun"""
|
|
|
|
return len(self.parcours) == self.competence.referentiel.parcours.count()
|
|
|
|
|
2022-04-29 08:17:04 +02:00
|
|
|
@classmethod
|
|
|
|
def niveaux_annee_de_parcours(
|
2022-06-22 14:09:08 +02:00
|
|
|
cls,
|
|
|
|
parcour: "ApcParcours",
|
|
|
|
annee: int,
|
|
|
|
referentiel_competence: ApcReferentielCompetences = None,
|
2023-04-07 17:10:17 +02:00
|
|
|
competence: ApcCompetence = None,
|
2023-03-26 10:08:50 +02:00
|
|
|
) -> list["ApcNiveau"]:
|
2022-06-22 14:09:08 +02:00
|
|
|
"""Les niveaux de l'année du parcours
|
|
|
|
Si le parcour est None, tous les niveaux de l'année
|
2023-04-07 17:10:17 +02:00
|
|
|
(dans ce cas, spécifier referentiel_competence)
|
|
|
|
Si competence est indiquée, filtre les niveaux de cette compétence.
|
2022-06-22 14:09:08 +02:00
|
|
|
"""
|
2023-06-21 12:33:45 +02:00
|
|
|
key = (
|
|
|
|
parcour.id if parcour else None,
|
|
|
|
annee,
|
|
|
|
referentiel_competence.id if referentiel_competence else None,
|
|
|
|
competence.id if competence else None,
|
|
|
|
)
|
2023-06-21 13:09:04 +02:00
|
|
|
_cache = getattr(g, "_niveaux_annee_de_parcours_cache", None)
|
|
|
|
if _cache:
|
|
|
|
result = g._niveaux_annee_de_parcours_cache.get(key, False)
|
|
|
|
if result is not False:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
g._niveaux_annee_de_parcours_cache = {}
|
|
|
|
_cache = g._niveaux_annee_de_parcours_cache
|
2022-04-29 08:17:04 +02:00
|
|
|
if annee not in {1, 2, 3}:
|
|
|
|
raise ValueError("annee invalide pour un parcours BUT")
|
2023-03-26 10:08:50 +02:00
|
|
|
referentiel_competence = (
|
|
|
|
parcour.referentiel if parcour else referentiel_competence
|
|
|
|
)
|
2022-06-25 22:54:46 +02:00
|
|
|
if referentiel_competence is None:
|
2023-01-03 13:06:11 +01:00
|
|
|
raise ScoNoReferentielCompetences()
|
2023-03-26 10:08:50 +02:00
|
|
|
if not parcour:
|
|
|
|
annee_formation = f"BUT{annee}"
|
2023-04-07 17:10:17 +02:00
|
|
|
query = ApcNiveau.query.filter(
|
2022-06-22 14:09:08 +02:00
|
|
|
ApcNiveau.annee == annee_formation,
|
|
|
|
ApcCompetence.id == ApcNiveau.competence_id,
|
|
|
|
ApcCompetence.referentiel_id == referentiel_competence.id,
|
|
|
|
)
|
2023-04-07 17:10:17 +02:00
|
|
|
if competence is not None:
|
|
|
|
query = query.filter(ApcCompetence.id == competence.id)
|
2023-06-21 12:33:45 +02:00
|
|
|
result = query.all()
|
2023-06-21 13:09:04 +02:00
|
|
|
_cache[key] = result
|
2023-06-21 12:33:45 +02:00
|
|
|
return result
|
2023-04-07 17:10:17 +02:00
|
|
|
|
|
|
|
annee_parcour: ApcAnneeParcours = parcour.annees.filter_by(ordre=annee).first()
|
2023-03-26 10:08:50 +02:00
|
|
|
if not annee_parcour:
|
2023-06-21 13:09:04 +02:00
|
|
|
_cache[key] = []
|
2023-03-26 10:08:50 +02:00
|
|
|
return []
|
|
|
|
|
2023-04-07 17:10:17 +02:00
|
|
|
if competence is None:
|
2024-04-05 23:41:34 +02:00
|
|
|
parcour_niveaux: list[ApcParcoursNiveauCompetence] = (
|
|
|
|
annee_parcour.niveaux_competences
|
|
|
|
)
|
2023-04-07 17:10:17 +02:00
|
|
|
niveaux: list[ApcNiveau] = [
|
|
|
|
pn.competence.niveaux.filter_by(ordre=pn.niveau).first()
|
|
|
|
for pn in parcour_niveaux
|
|
|
|
]
|
|
|
|
else:
|
2023-08-10 19:08:01 +02:00
|
|
|
niveaux: list[ApcNiveau] = (
|
|
|
|
ApcNiveau.query.filter_by(annee=f"BUT{int(annee)}")
|
|
|
|
.join(ApcCompetence)
|
|
|
|
.filter_by(id=competence.id)
|
|
|
|
.join(ApcParcoursNiveauCompetence)
|
|
|
|
.filter(ApcParcoursNiveauCompetence.niveau == ApcNiveau.ordre)
|
|
|
|
.join(ApcAnneeParcours)
|
|
|
|
.filter_by(parcours_id=parcour.id)
|
|
|
|
.all()
|
|
|
|
)
|
2023-06-21 13:09:04 +02:00
|
|
|
_cache[key] = niveaux
|
2023-03-26 10:08:50 +02:00
|
|
|
return niveaux
|
2022-04-29 08:17:04 +02:00
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-05-02 14:39:06 +02:00
|
|
|
app_critiques_modules = db.Table(
|
|
|
|
"apc_modules_acs",
|
|
|
|
db.Column(
|
|
|
|
"module_id",
|
|
|
|
db.ForeignKey("notes_modules.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
|
|
|
),
|
|
|
|
db.Column(
|
|
|
|
"app_crit_id",
|
2023-02-09 11:56:20 +01:00
|
|
|
db.ForeignKey("apc_app_critique.id", ondelete="CASCADE"),
|
2022-05-02 14:39:06 +02:00
|
|
|
primary_key=True,
|
|
|
|
),
|
2024-07-10 18:27:13 +02:00
|
|
|
db.UniqueConstraint("module_id", "app_crit_id", name="uix_module_id_app_crit_id"),
|
2022-05-02 14:39:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcAppCritique(models.ScoDocModel, XMLModel):
|
2021-12-02 12:08:03 +01:00
|
|
|
"Apprentissage Critique BUT"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-02-09 11:56:20 +01:00
|
|
|
niveau_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("apc_niveau.id", ondelete="CASCADE"), nullable=False
|
|
|
|
)
|
2021-12-03 11:03:33 +01:00
|
|
|
code = db.Column(db.Text(), nullable=False, index=True)
|
2021-12-02 12:08:03 +01:00
|
|
|
libelle = db.Column(db.Text())
|
|
|
|
|
2022-05-02 14:39:06 +02:00
|
|
|
# modules = db.relationship(
|
|
|
|
# "Module",
|
|
|
|
# secondary="apc_modules_acs",
|
|
|
|
# lazy="dynamic",
|
|
|
|
# backref=db.backref("app_critiques", lazy="dynamic"),
|
|
|
|
# )
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def app_critiques_ref_comp(
|
|
|
|
cls,
|
|
|
|
ref_comp: ApcReferentielCompetences,
|
|
|
|
annee: str,
|
|
|
|
competence: ApcCompetence = None,
|
2023-04-03 17:40:45 +02:00
|
|
|
) -> Query:
|
2022-05-02 14:39:06 +02:00
|
|
|
"Liste les AC de tous les parcours de ref_comp pour l'année indiquée"
|
|
|
|
assert annee in {"BUT1", "BUT2", "BUT3"}
|
|
|
|
query = cls.query.filter(
|
|
|
|
ApcAppCritique.niveau_id == ApcNiveau.id,
|
|
|
|
ApcNiveau.competence_id == ApcCompetence.id,
|
|
|
|
ApcNiveau.annee == annee,
|
|
|
|
ApcCompetence.referentiel_id == ref_comp.id,
|
|
|
|
)
|
|
|
|
if competence is not None:
|
|
|
|
query = query.filter(ApcNiveau.competence == competence)
|
|
|
|
return query
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-10-24 23:18:45 +02:00
|
|
|
def to_dict(self, with_code=False) -> dict:
|
|
|
|
if with_code:
|
|
|
|
return {"code": self.code, "libelle": self.libelle}
|
2021-12-03 15:44:57 +01:00
|
|
|
return {"libelle": self.libelle}
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-04-26 06:02:17 +02:00
|
|
|
def get_label(self) -> str:
|
2021-12-02 12:08:03 +01:00
|
|
|
return self.code + " - " + self.titre
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-05-22 03:26:39 +02:00
|
|
|
return f"<{self.__class__.__name__} {self.code!r}>"
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
def get_saes(self):
|
|
|
|
"""Liste des SAE associées"""
|
|
|
|
return [m for m in self.modules if m.module_type == ModuleType.SAE]
|
|
|
|
|
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
parcours_modules = db.Table(
|
|
|
|
"parcours_modules",
|
|
|
|
db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
"parcours_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_parcours.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
2022-05-01 23:58:41 +02:00
|
|
|
),
|
|
|
|
db.Column(
|
|
|
|
"module_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_modules.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
"""Association parcours <-> modules (many-to-many)"""
|
|
|
|
|
2022-05-22 03:26:39 +02:00
|
|
|
parcours_formsemestre = db.Table(
|
|
|
|
"parcours_formsemestre",
|
|
|
|
db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
"parcours_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_parcours.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
2022-05-22 03:26:39 +02:00
|
|
|
),
|
|
|
|
db.Column(
|
|
|
|
"formsemestre_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
"""Association parcours <-> formsemestre (many-to-many)"""
|
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcParcours(models.ScoDocModel, XMLModel):
|
2022-10-07 22:37:06 +02:00
|
|
|
"Un parcours BUT"
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
referentiel_id = db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_referentiel_competences.id", ondelete="CASCADE"),
|
|
|
|
nullable=False,
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
2023-04-03 17:46:31 +02:00
|
|
|
numero = db.Column(db.Integer, nullable=False, default=0) # ordre de présentation
|
2021-12-02 12:08:03 +01:00
|
|
|
code = db.Column(db.Text(), nullable=False)
|
|
|
|
libelle = db.Column(db.Text(), nullable=False)
|
|
|
|
annees = db.relationship(
|
|
|
|
"ApcAnneeParcours",
|
|
|
|
backref="parcours",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
|
|
|
|
2022-08-31 12:02:19 +02:00
|
|
|
def __repr__(self) -> str:
|
2022-07-10 12:08:22 +02:00
|
|
|
return f"<{self.__class__.__name__} {self.id} {self.code!r} ref={self.referentiel}>"
|
2022-04-26 06:02:17 +02:00
|
|
|
|
2022-08-31 12:02:19 +02:00
|
|
|
def to_dict(self, with_annees=True) -> dict:
|
|
|
|
"""dict repr.
|
|
|
|
On peut ne pas indiquer les années pour gagner de la place (export formations).
|
|
|
|
"""
|
|
|
|
d = {
|
2021-12-02 17:36:32 +01:00
|
|
|
"code": self.code,
|
|
|
|
"numero": self.numero,
|
|
|
|
"libelle": self.libelle,
|
|
|
|
}
|
2022-08-31 12:02:19 +02:00
|
|
|
if with_annees:
|
|
|
|
d["annees"] = {x.ordre: x.to_dict() for x in self.annees}
|
|
|
|
return d
|
2021-12-02 17:36:32 +01:00
|
|
|
|
2023-04-03 17:40:45 +02:00
|
|
|
def query_competences(self) -> Query:
|
2023-01-17 01:05:48 +01:00
|
|
|
"Les compétences associées à ce parcours"
|
|
|
|
return (
|
2023-07-10 13:58:16 +02:00
|
|
|
ApcCompetence.query.join(ApcParcoursNiveauCompetence)
|
|
|
|
.join(ApcAnneeParcours)
|
2023-01-17 01:05:48 +01:00
|
|
|
.filter_by(parcours_id=self.id)
|
|
|
|
.order_by(ApcCompetence.numero)
|
|
|
|
)
|
|
|
|
|
2023-04-07 17:10:17 +02:00
|
|
|
def get_competence_by_titre(self, titre: str) -> ApcCompetence:
|
|
|
|
"La compétence de titre donné dans ce parcours, ou None"
|
|
|
|
return (
|
|
|
|
ApcCompetence.query.filter_by(titre=titre)
|
2023-07-10 13:58:16 +02:00
|
|
|
.join(ApcParcoursNiveauCompetence)
|
|
|
|
.join(ApcAnneeParcours)
|
2023-04-07 17:10:17 +02:00
|
|
|
.filter_by(parcours_id=self.id)
|
|
|
|
.order_by(ApcCompetence.numero)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcAnneeParcours(models.ScoDocModel, XMLModel):
|
2021-12-02 12:08:03 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
parcours_id = db.Column(
|
2023-02-09 11:56:20 +01:00
|
|
|
db.Integer, db.ForeignKey("apc_parcours.id", ondelete="CASCADE"), nullable=False
|
2021-12-02 12:08:03 +01:00
|
|
|
)
|
2021-12-02 17:36:32 +01:00
|
|
|
ordre = db.Column(db.Integer)
|
2022-04-29 08:17:04 +02:00
|
|
|
"numéro de l'année: 1, 2, 3"
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-04-26 06:02:17 +02:00
|
|
|
def __repr__(self):
|
2023-04-10 11:25:46 +02:00
|
|
|
return f"""<{self.__class__.__name__} {
|
|
|
|
self.id} ordre={self.ordre!r} parcours={self.parcours.code!r}>"""
|
2022-04-26 06:02:17 +02:00
|
|
|
|
2021-12-02 17:36:32 +01:00
|
|
|
def to_dict(self):
|
|
|
|
return {
|
|
|
|
"ordre": self.ordre,
|
|
|
|
"competences": {
|
2022-01-08 17:22:51 +01:00
|
|
|
x.competence.titre: {
|
|
|
|
"niveau": x.niveau,
|
|
|
|
"id_orebut": x.competence.id_orebut,
|
|
|
|
}
|
2021-12-02 17:36:32 +01:00
|
|
|
for x in self.niveaux_competences
|
|
|
|
},
|
|
|
|
}
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
class ApcParcoursNiveauCompetence(models.ScoDocModel):
|
2021-12-02 12:08:03 +01:00
|
|
|
"""Association entre année de parcours et compétence.
|
|
|
|
Le "niveau" de la compétence est donné ici
|
|
|
|
(convention Orébut)
|
|
|
|
"""
|
|
|
|
|
|
|
|
competence_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_competence.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
|
|
|
)
|
|
|
|
annee_parcours_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("apc_annee_parcours.id", ondelete="CASCADE"),
|
|
|
|
primary_key=True,
|
|
|
|
)
|
|
|
|
niveau = db.Column(db.Integer, nullable=False) # 1, 2, 3
|
|
|
|
competence = db.relationship(
|
|
|
|
ApcCompetence,
|
|
|
|
backref=db.backref(
|
|
|
|
"annee_parcours",
|
|
|
|
passive_deletes=True,
|
|
|
|
cascade="save-update, merge, delete, delete-orphan",
|
2022-04-29 08:17:04 +02:00
|
|
|
lazy="dynamic",
|
2021-12-02 12:08:03 +01:00
|
|
|
),
|
|
|
|
)
|
|
|
|
annee_parcours = db.relationship(
|
|
|
|
ApcAnneeParcours,
|
|
|
|
backref=db.backref(
|
2021-12-02 17:36:32 +01:00
|
|
|
"niveaux_competences",
|
2021-12-02 12:08:03 +01:00
|
|
|
passive_deletes=True,
|
|
|
|
cascade="save-update, merge, delete, delete-orphan",
|
|
|
|
),
|
|
|
|
)
|
2022-04-26 06:02:17 +02:00
|
|
|
|
|
|
|
def __repr__(self):
|
2022-05-22 03:26:39 +02:00
|
|
|
return f"<{self.__class__.__name__} {self.competence!r}<->{self.annee_parcours!r} niveau={self.niveau!r}>"
|