2021-12-03 14:13:49 +01:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-01-02 13:16:27 +01:00
|
|
|
# Copyright (c) 1999 - 2023 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
|
2021-12-02 12:08:03 +01:00
|
|
|
|
2022-04-29 08:17:04 +02:00
|
|
|
import flask_sqlalchemy
|
2022-01-03 12:25:42 +01:00
|
|
|
from sqlalchemy.orm import class_mapper
|
|
|
|
import sqlalchemy
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
from app import db
|
|
|
|
|
|
|
|
from app.scodoc.sco_utils import ModuleType
|
2023-01-03 13:06:11 +01:00
|
|
|
from app.scodoc.sco_exceptions import ScoNoReferentielCompetences
|
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 ""}">'
|
|
|
|
|
|
|
|
|
|
|
|
class ApcReferentielCompetences(db.Model, 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-03-26 10:08:50 +02:00
|
|
|
formations = db.relationship(
|
|
|
|
"Formation",
|
|
|
|
backref="referentiel_competence",
|
|
|
|
order_by="Formation.acronyme, Formation.version",
|
|
|
|
)
|
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
|
|
|
|
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,
|
2021-12-03 15:44:57 +01: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(
|
2022-12-20 04:16:38 +01:00
|
|
|
self, annee: int, parcour: "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
|
2022-10-30 16:07:06 +01:00
|
|
|
de ce référentiel, ou seulement pour le parcours donné.
|
|
|
|
|
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()
|
|
|
|
if parcour is None:
|
|
|
|
parcours = parcours_ref
|
|
|
|
else:
|
|
|
|
parcours = [parcour]
|
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
|
|
|
|
],
|
|
|
|
key=lambda c: c.numero or 0,
|
|
|
|
)
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
class ApcCompetence(db.Model, 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())
|
|
|
|
numero = db.Column(db.Integer) # ordre de présentation
|
|
|
|
_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
|
|
|
|
|
|
|
class ApcSituationPro(db.Model, 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)
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
|
class ApcComposanteEssentielle(db.Model, 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
|
|
|
|
|
|
|
class ApcNiveau(db.Model, 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-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,
|
2023-01-17 01:05:48 +01: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(),
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
"""
|
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}"
|
2022-06-22 14:09:08 +02:00
|
|
|
return ApcNiveau.query.filter(
|
|
|
|
ApcNiveau.annee == annee_formation,
|
|
|
|
ApcCompetence.id == ApcNiveau.competence_id,
|
|
|
|
ApcCompetence.referentiel_id == referentiel_competence.id,
|
|
|
|
)
|
2023-03-26 10:08:50 +02:00
|
|
|
annee_parcour = parcour.annees.filter_by(ordre=annee).first()
|
|
|
|
if not annee_parcour:
|
|
|
|
return []
|
|
|
|
|
|
|
|
parcour_niveaux: list[
|
|
|
|
ApcParcoursNiveauCompetence
|
|
|
|
] = annee_parcour.niveaux_competences
|
|
|
|
niveaux: list[ApcNiveau] = [
|
|
|
|
pn.competence.niveaux.filter_by(ordre=pn.niveau).first()
|
|
|
|
for pn in parcour_niveaux
|
|
|
|
]
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
class ApcAppCritique(db.Model, XMLModel):
|
|
|
|
"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,
|
|
|
|
) -> flask_sqlalchemy.BaseQuery:
|
|
|
|
"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
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
class ApcParcours(db.Model, 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
|
|
|
)
|
|
|
|
numero = db.Column(db.Integer) # ordre de présentation
|
|
|
|
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-10-30 16:07:06 +01:00
|
|
|
ues = db.relationship("UniteEns", back_populates="parcour")
|
2021-12-02 12:08:03 +01:00
|
|
|
|
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-01-17 01:05:48 +01:00
|
|
|
def query_competences(self) -> flask_sqlalchemy.BaseQuery:
|
|
|
|
"Les compétences associées à ce parcours"
|
|
|
|
return (
|
|
|
|
ApcCompetence.query.join(ApcParcoursNiveauCompetence, ApcAnneeParcours)
|
|
|
|
.filter_by(parcours_id=self.id)
|
|
|
|
.order_by(ApcCompetence.numero)
|
|
|
|
)
|
|
|
|
|
2021-12-02 12:08:03 +01:00
|
|
|
|
|
|
|
class ApcAnneeParcours(db.Model, XMLModel):
|
|
|
|
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):
|
2022-07-10 12:08:22 +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
|
|
|
|
|
|
|
|
|
|
|
class ApcParcoursNiveauCompetence(db.Model):
|
|
|
|
"""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}>"
|