diff --git a/app/models/modules.py b/app/models/modules.py index 430835a9..2c3a9131 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -1,6 +1,6 @@ """ScoDoc 9 models : Modules """ -from flask import current_app +from flask import current_app, g from app import db from app.models import APO_CODE_STR_LEN @@ -310,6 +310,14 @@ class Module(db.Model): return [] return self.parcours + def add_tag(self, tag: "NotesTag"): + """Add tag to module. Check if already has it.""" + if tag.id in {t.id for t in self.tags}: + return + self.tags.append(tag) + db.session.add(self) + db.session.flush() + class ModuleUECoef(db.Model): """Coefficients des modules vers les UE (APC, BUT) @@ -372,6 +380,19 @@ class NotesTag(db.Model): dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True) title = db.Column(db.Text(), nullable=False) + @classmethod + def get_or_create(cls, title: str, dept_id: int | None = None) -> "NotesTag": + """Get tag, or create it if it doesn't yet exists. + If dept_id unspecified, use current dept. + """ + dept_id = dept_id if dept_id is not None else g.scodoc_dept_id + tag = NotesTag.query.filter_by(dept_id=dept_id, title=title).first() + if tag is None: + tag = NotesTag(dept_id=dept_id, title=title) + db.session.add(tag) + db.session.flush() + return tag + # Association tag <-> module notes_modules_tags = db.Table( diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index f33eeacd..dd95dfd3 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -670,6 +670,7 @@ def ue_table(formation_id=None, semestre_idx=1, msg=""): # was ue_list semestre_idx = None else: semestre_idx = int(semestre_idx) + show_tags = scu.to_bool(request.args.get("show_tags", 0)) locked = formation.has_locked_sems(semestre_idx) semestre_ids = range(1, parcours.NB_SEM + 1) # transition: on requete ici via l'ORM mais on utilise les fonctions ScoDoc7 @@ -875,11 +876,13 @@ du programme" (menu "Semestre") si vous avez un semestre en cours); ) # Description des UE/matières/modules H.append( - """ + f"""