2021-08-07 15:20:30 +02:00
|
|
|
"""ScoDoc8 models : Formations (hors BUT)
|
|
|
|
"""
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
from app.models import APO_CODE_STR_LEN
|
|
|
|
from app.models import SHORT_STR_LEN
|
2021-11-22 00:31:53 +01:00
|
|
|
from app.scodoc import notesdb as ndb
|
2021-11-12 22:17:46 +01:00
|
|
|
from app.scodoc import sco_utils as scu
|
2021-11-08 19:44:25 +01:00
|
|
|
from app.scodoc.sco_utils import ModuleType
|
2021-11-14 18:09:20 +01:00
|
|
|
from app.scodoc import sco_codes_parcours
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
class Formation(db.Model):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Programme pédagogique d'une formation"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_formations"
|
2021-09-19 21:31:35 +02:00
|
|
|
__table_args__ = (db.UniqueConstraint("dept_id", "acronyme", "titre", "version"),)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
formation_id = db.synonym("id")
|
2021-08-13 00:34:58 +02:00
|
|
|
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True)
|
|
|
|
|
2021-08-15 22:33:09 +02:00
|
|
|
acronyme = db.Column(db.Text(), nullable=False)
|
2021-08-07 15:20:30 +02:00
|
|
|
titre = db.Column(db.Text(), nullable=False)
|
2021-08-08 16:01:10 +02:00
|
|
|
titre_officiel = db.Column(db.Text(), nullable=False)
|
2021-08-10 00:23:30 +02:00
|
|
|
version = db.Column(db.Integer, default=1, server_default="1")
|
2021-08-08 16:01:10 +02:00
|
|
|
formation_code = db.Column(
|
|
|
|
db.String(SHORT_STR_LEN),
|
|
|
|
server_default=db.text("notes_newid_fcod()"),
|
|
|
|
nullable=False,
|
|
|
|
)
|
|
|
|
# nb: la fonction SQL notes_newid_fcod doit être créée à part
|
2021-08-10 00:23:30 +02:00
|
|
|
type_parcours = db.Column(db.Integer, default=0, server_default="0")
|
2021-08-07 15:20:30 +02:00
|
|
|
code_specialite = db.Column(db.String(SHORT_STR_LEN))
|
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
ues = db.relationship("UniteEns", backref="formation", lazy="dynamic")
|
2021-08-13 00:34:58 +02:00
|
|
|
formsemestres = db.relationship("FormSemestre", lazy="dynamic", backref="formation")
|
2021-11-12 22:17:46 +01:00
|
|
|
ues = db.relationship("UniteEns", lazy="dynamic", backref="formation")
|
2021-11-17 10:28:51 +01:00
|
|
|
modules = db.relationship("Module", lazy="dynamic", backref="formation")
|
2021-08-13 00:34:58 +02:00
|
|
|
|
2021-09-26 11:28:13 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return f"<{self.__class__.__name__}(id={self.id}, dept_id={self.dept_id}, acronyme='{self.acronyme}')>"
|
|
|
|
|
2021-11-14 18:09:20 +01:00
|
|
|
def get_parcours(self):
|
|
|
|
"""get l'instance de TypeParcours de cette formation"""
|
|
|
|
return sco_codes_parcours.get_parcours_from_code(self.type_parcours)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
class UniteEns(db.Model):
|
|
|
|
"""Unité d'Enseignement (UE)"""
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
__tablename__ = "notes_ue"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
ue_id = db.synonym("id")
|
|
|
|
formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id"))
|
2021-08-15 22:41:47 +02:00
|
|
|
acronyme = db.Column(db.Text(), nullable=False)
|
2021-08-07 15:20:30 +02:00
|
|
|
numero = db.Column(db.Integer) # ordre de présentation
|
|
|
|
titre = db.Column(db.Text())
|
2021-11-14 18:09:20 +01:00
|
|
|
# Le semestre_idx n'est pas un id mais le numéro du semestre: 1, 2, ...
|
|
|
|
# En ScoDoc7 et pour les formations classiques, il est NULL
|
|
|
|
# (le numéro du semestre étant alors déterminé par celui des modules de l'UE)
|
|
|
|
# Pour les formations APC, il est obligatoire (de 1 à 6 pour le BUT):
|
|
|
|
semestre_idx = db.Column(db.Integer, nullable=True, index=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
# Type d'UE: 0 normal ("fondamentale"), 1 "sport", 2 "projet et stage (LP)",
|
|
|
|
# 4 "élective"
|
2021-08-10 00:23:30 +02:00
|
|
|
type = db.Column(db.Integer, default=0, server_default="0")
|
2021-08-08 16:01:10 +02:00
|
|
|
# Les UE sont "compatibles" (pour la capitalisation) ssi elles ont ^m code
|
|
|
|
# note: la fonction SQL notes_newid_ucod doit être créée à part
|
|
|
|
ue_code = db.Column(
|
|
|
|
db.String(SHORT_STR_LEN),
|
|
|
|
server_default=db.text("notes_newid_ucod()"),
|
|
|
|
nullable=False,
|
|
|
|
)
|
2021-08-07 15:20:30 +02:00
|
|
|
ects = db.Column(db.Float) # nombre de credits ECTS
|
2021-08-10 00:23:30 +02:00
|
|
|
is_external = db.Column(db.Boolean(), default=False, server_default="false")
|
2021-08-07 15:20:30 +02:00
|
|
|
# id de l'element pedagogique Apogee correspondant:
|
|
|
|
code_apogee = db.Column(db.String(APO_CODE_STR_LEN))
|
|
|
|
# coef UE, utilise seulement si l'option use_ue_coefs est activée:
|
|
|
|
coefficient = db.Column(db.Float)
|
|
|
|
|
2021-10-16 19:19:07 +02:00
|
|
|
# relations
|
2021-11-12 22:17:46 +01:00
|
|
|
matieres = db.relationship("Matiere", lazy="dynamic", backref="ue")
|
|
|
|
modules = db.relationship("Module", lazy="dynamic", backref="ue")
|
2021-10-16 19:19:07 +02:00
|
|
|
|
2021-09-26 11:28:13 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return f"<{self.__class__.__name__}(id={self.id}, formation_id={self.formation_id}, acronyme='{self.acronyme}')>"
|
|
|
|
|
2021-11-22 00:31:53 +01:00
|
|
|
def to_dict(self):
|
|
|
|
"""as a dict, with the same conversions as in ScoDoc7"""
|
|
|
|
e = dict(self.__dict__)
|
|
|
|
e.pop("_sa_instance_state", None)
|
|
|
|
# ScoDoc7 output_formators
|
|
|
|
e["numero"] = e["numero"] if e["numero"] else 0
|
|
|
|
e["ects"] = e["ects"] if e["ects"] else 0.0
|
|
|
|
e["coefficient"] = e["coefficient"] if e["coefficient"] else 0.0
|
|
|
|
return e
|
|
|
|
|
2021-11-18 00:24:56 +01:00
|
|
|
def is_locked(self):
|
|
|
|
"""True if UE should not be modified
|
|
|
|
(contains modules used in a locked formsemestre)
|
|
|
|
"""
|
|
|
|
# XXX todo : à ré-écrire avec SQLAlchemy
|
|
|
|
from app.scodoc import sco_edit_ue
|
|
|
|
|
|
|
|
return sco_edit_ue.ue_is_locked(self.id)
|
|
|
|
|
2021-11-22 00:31:53 +01:00
|
|
|
def guess_semestre_idx(self) -> None:
|
|
|
|
"""Lorsqu'on prend une ancienne formation non APC,
|
|
|
|
les UE n'ont pas d'indication de semestre.
|
|
|
|
Cette méthode fixe le semestre en prenant celui du premier module,
|
|
|
|
ou à défaut le met à 1.
|
|
|
|
"""
|
|
|
|
if self.semestre_idx is None:
|
|
|
|
if self.modules:
|
|
|
|
self.semestre_idx = self.modules[0].semestre_id
|
|
|
|
else:
|
|
|
|
self.semestre_idx = 1
|
|
|
|
db.session.add(self)
|
|
|
|
db.session.commit()
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
class Matiere(db.Model):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Matières: regroupe les modules d'une UE
|
|
|
|
La matière a peu d'utilité en dehors de la présentation des modules
|
|
|
|
d'une UE.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_matieres"
|
|
|
|
__table_args__ = (db.UniqueConstraint("ue_id", "titre"),)
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
matiere_id = db.synonym("id")
|
|
|
|
ue_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"))
|
|
|
|
titre = db.Column(db.Text())
|
|
|
|
numero = db.Column(db.Integer) # ordre de présentation
|
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
modules = db.relationship("Module", lazy="dynamic", backref="matiere")
|
2021-10-16 19:19:07 +02:00
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
class Module(db.Model):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Module"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_modules"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
module_id = db.synonym("id")
|
|
|
|
titre = db.Column(db.Text())
|
|
|
|
abbrev = db.Column(db.Text()) # nom court
|
2021-08-27 17:03:47 +02:00
|
|
|
# certains départements ont des codes infiniment longs: donc Text !
|
|
|
|
code = db.Column(db.Text(), nullable=False)
|
2021-08-07 15:20:30 +02:00
|
|
|
heures_cours = db.Column(db.Float)
|
|
|
|
heures_td = db.Column(db.Float)
|
|
|
|
heures_tp = db.Column(db.Float)
|
2021-11-12 22:17:46 +01:00
|
|
|
coefficient = db.Column(db.Float) # coef PPN (sauf en APC)
|
2021-08-09 11:33:04 +02:00
|
|
|
ects = db.Column(db.Float) # Crédits ECTS
|
2021-08-08 17:38:46 +02:00
|
|
|
ue_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), index=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id"))
|
|
|
|
matiere_id = db.Column(db.Integer, db.ForeignKey("notes_matieres.id"))
|
|
|
|
# pas un id mais le numéro du semestre: 1, 2, ...
|
2021-08-10 00:23:30 +02:00
|
|
|
semestre_id = db.Column(db.Integer, nullable=False, default=1, server_default="1")
|
2021-08-07 15:20:30 +02:00
|
|
|
numero = db.Column(db.Integer) # ordre de présentation
|
|
|
|
# id de l'element pedagogique Apogee correspondant:
|
|
|
|
code_apogee = db.Column(db.String(APO_CODE_STR_LEN))
|
2021-11-08 19:44:25 +01:00
|
|
|
# Type: ModuleType: DEFAULT, MALUS, RESSOURCE, MODULE_SAE (enum)
|
|
|
|
module_type = db.Column(db.Integer)
|
2021-10-16 19:19:07 +02:00
|
|
|
# Relations:
|
2021-11-12 22:17:46 +01:00
|
|
|
modimpls = db.relationship("ModuleImpl", backref="module", lazy="dynamic")
|
|
|
|
ues_apc = db.relationship("UniteEns", secondary="module_ue_coef", viewonly=True)
|
2021-11-17 10:28:51 +01:00
|
|
|
tags = db.relationship(
|
|
|
|
"NotesTag",
|
|
|
|
secondary="notes_modules_tags",
|
|
|
|
lazy=True,
|
|
|
|
backref=db.backref("modules", lazy=True),
|
|
|
|
)
|
2021-11-12 22:17:46 +01:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
self.ue_coefs = []
|
|
|
|
super(Module, self).__init__(**kwargs)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2021-11-08 19:44:25 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return (
|
|
|
|
f"<Module{ModuleType(self.module_type).name} id={self.id} code={self.code}>"
|
|
|
|
)
|
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
def type_name(self):
|
|
|
|
return scu.MODULE_TYPE_NAMES[self.module_type]
|
|
|
|
|
|
|
|
def set_ue_coef(self, ue, coef: float) -> None:
|
|
|
|
"""Set coef module vers cette UE"""
|
|
|
|
self.update_ue_coef_dict({ue.id: coef})
|
|
|
|
|
|
|
|
def set_ue_coef_dict(self, ue_coef_dict: dict) -> None:
|
|
|
|
"""set coefs vers les UE (remplace existants)
|
|
|
|
ue_coef_dict = { ue_id : coef }
|
2021-11-13 12:09:30 +01:00
|
|
|
Les coefs nuls (zéro) ne sont pas stockés: la relation est supprimée.
|
2021-11-12 22:17:46 +01:00
|
|
|
"""
|
|
|
|
ue_coefs = []
|
|
|
|
for ue_id, coef in ue_coef_dict.items():
|
|
|
|
ue = UniteEns.query.get(ue_id)
|
2021-11-13 12:09:30 +01:00
|
|
|
if coef == 0.0:
|
|
|
|
self.delete_ue_coef(ue)
|
|
|
|
else:
|
|
|
|
ue_coefs.append(ModuleUECoef(module=self, ue=ue, coef=coef))
|
2021-11-12 22:17:46 +01:00
|
|
|
self.ue_coefs = ue_coefs
|
|
|
|
|
|
|
|
def update_ue_coef_dict(self, ue_coef_dict: dict):
|
|
|
|
"""update coefs vers UE (ajoute aux existants)"""
|
|
|
|
current = self.get_ue_coef_dict()
|
|
|
|
current.update(ue_coef_dict)
|
|
|
|
self.set_ue_coef_dict(current)
|
|
|
|
|
|
|
|
def get_ue_coef_dict(self):
|
|
|
|
"""returns { ue_id : coef }"""
|
|
|
|
return {p.ue.id: p.coef for p in self.ue_coefs}
|
|
|
|
|
|
|
|
def delete_ue_coef(self, ue):
|
|
|
|
"""delete coef"""
|
|
|
|
ue_coef = ModuleUECoef.query.get((self.id, ue.id))
|
2021-11-13 12:09:30 +01:00
|
|
|
if ue_coef:
|
|
|
|
db.session.delete(ue_coef)
|
|
|
|
|
|
|
|
def ue_coefs_descr(self):
|
|
|
|
"""List of tuples [ (ue_acronyme, coef) ]"""
|
|
|
|
return [(c.ue.acronyme, c.coef) for c in self.ue_coefs]
|
2021-11-12 22:17:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ModuleUECoef(db.Model):
|
|
|
|
"""Coefficients des modules vers les UE (APC, BUT)
|
|
|
|
En mode APC, ces coefs remplacent le coefficient "PPN" du module.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "module_ue_coef"
|
|
|
|
|
|
|
|
module_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("notes_modules.id"), primary_key=True
|
|
|
|
)
|
|
|
|
ue_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), primary_key=True)
|
|
|
|
coef = db.Column(
|
|
|
|
db.Float,
|
|
|
|
nullable=False,
|
|
|
|
)
|
|
|
|
module = db.relationship(
|
|
|
|
Module,
|
|
|
|
backref=db.backref("ue_coefs", cascade="all, delete-orphan"),
|
|
|
|
)
|
|
|
|
ue = db.relationship(
|
|
|
|
UniteEns,
|
|
|
|
backref=db.backref("module_ue_coefs", cascade="all, delete-orphan"),
|
|
|
|
)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
class NotesTag(db.Model):
|
|
|
|
"""Tag sur un module"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_tags"
|
2021-08-18 22:20:20 +02:00
|
|
|
__table_args__ = (db.UniqueConstraint("title", "dept_id"),)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
tag_id = db.synonym("id")
|
2021-08-18 22:20:20 +02:00
|
|
|
|
|
|
|
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True)
|
|
|
|
title = db.Column(db.Text(), nullable=False)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Association tag <-> module
|
|
|
|
notes_modules_tags = db.Table(
|
|
|
|
"notes_modules_tags",
|
2021-10-26 10:22:55 +02:00
|
|
|
db.Column(
|
|
|
|
"tag_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_tags.id", ondelete="CASCADE"),
|
|
|
|
),
|
|
|
|
db.Column(
|
|
|
|
"module_id", db.Integer, db.ForeignKey("notes_modules.id", ondelete="CASCADE")
|
|
|
|
),
|
2021-08-07 15:20:30 +02:00
|
|
|
)
|