2021-08-07 15:20:30 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
2022-07-20 15:07:31 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2022-07-20 15:07:31 +02:00
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2022-11-13 14:55:18 +01:00
|
|
|
# pylint génère trop de faux positifs avec les colonnes date:
|
|
|
|
# pylint: disable=no-member,not-an-iterable
|
|
|
|
|
2021-11-13 08:25:51 +01:00
|
|
|
"""ScoDoc models: formsemestre
|
2021-08-07 15:20:30 +02:00
|
|
|
"""
|
2023-12-29 13:58:18 +01:00
|
|
|
from collections import defaultdict
|
2021-12-04 21:04:09 +01:00
|
|
|
import datetime
|
2021-12-30 23:58:38 +01:00
|
|
|
from functools import cached_property
|
2023-12-29 13:58:18 +01:00
|
|
|
from itertools import chain
|
2023-04-03 17:46:31 +02:00
|
|
|
from operator import attrgetter
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2023-02-12 01:13:43 +01:00
|
|
|
from flask_login import current_user
|
2023-04-03 17:40:45 +02:00
|
|
|
|
2023-12-31 22:18:52 +01:00
|
|
|
from flask import abort, flash, g, url_for
|
2024-10-18 23:37:16 +02:00
|
|
|
from flask_sqlalchemy.query import Query
|
2022-07-05 16:09:26 +02:00
|
|
|
from sqlalchemy.sql import text
|
2023-09-11 17:58:12 +02:00
|
|
|
from sqlalchemy import func
|
2021-11-17 10:28:51 +01:00
|
|
|
|
2022-11-13 14:55:18 +01:00
|
|
|
import app.scodoc.sco_utils as scu
|
2024-08-22 16:42:38 +02:00
|
|
|
from app import db, email, log
|
2023-02-12 01:13:43 +01:00
|
|
|
from app.auth.models import User
|
2024-03-19 18:22:02 +01:00
|
|
|
from app import models
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.models import APO_CODE_STR_LEN, CODE_STR_LEN, SHORT_STR_LEN
|
2022-07-05 16:09:26 +02:00
|
|
|
from app.models.but_refcomp import (
|
|
|
|
ApcParcours,
|
2022-07-10 12:08:22 +02:00
|
|
|
ApcReferentielCompetences,
|
2022-11-13 14:55:18 +01:00
|
|
|
parcours_formsemestre,
|
2022-07-05 16:09:26 +02:00
|
|
|
)
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.models.config import ScoDocSiteConfig
|
2023-11-26 18:28:56 +01:00
|
|
|
from app.models.departements import Departement
|
2022-07-05 16:09:26 +02:00
|
|
|
from app.models.etudiants import Identite
|
2023-08-25 17:58:57 +02:00
|
|
|
from app.models.evaluations import Evaluation
|
2024-08-11 23:24:40 +02:00
|
|
|
from app.models.events import Scolog, ScolarNews
|
2022-10-01 10:39:46 +02:00
|
|
|
from app.models.formations import Formation
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.models.groups import GroupDescr, Partition
|
2023-12-29 13:58:18 +01:00
|
|
|
from app.models.moduleimpls import (
|
|
|
|
ModuleImpl,
|
|
|
|
ModuleImplInscription,
|
|
|
|
notes_modules_enseignants,
|
|
|
|
)
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.models.modules import Module
|
2024-08-11 23:24:40 +02:00
|
|
|
from app.models.scolar_event import ScolarEvent
|
2022-07-05 16:09:26 +02:00
|
|
|
from app.models.ues import UniteEns
|
2022-10-01 10:39:46 +02:00
|
|
|
from app.models.validations import ScolarFormSemestreValidation
|
2024-08-11 23:24:40 +02:00
|
|
|
from app.scodoc import codes_cursus, sco_cache, sco_preferences
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
2022-02-01 17:42:43 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2023-08-19 16:17:21 +02:00
|
|
|
from app.scodoc.sco_utils import MONTH_NAMES_ABBREV, translate_assiduites_metric
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.scodoc.sco_vdi import ApoEtapeVDI
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2023-05-15 23:39:08 +02:00
|
|
|
GROUPS_AUTO_ASSIGNMENT_DATA_MAX = 1024 * 1024 # bytes
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-03-19 18:22:02 +01:00
|
|
|
class FormSemestre(models.ScoDocModel):
|
2021-11-13 08:25:51 +01:00
|
|
|
"""Mise en oeuvre d'un semestre de formation"""
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
__tablename__ = "notes_formsemestre"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
formsemestre_id = db.synonym("id")
|
2021-09-13 22:10:01 +02:00
|
|
|
# dept_id est aussi dans la formation, ajouté ici pour
|
2021-08-13 00:34:58 +02:00
|
|
|
# simplifier et accélérer les selects dans notesdb
|
|
|
|
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id"))
|
2021-08-10 00:23:30 +02:00
|
|
|
semestre_id = db.Column(db.Integer, nullable=False, default=1, server_default="1")
|
2023-01-09 12:12:31 +01:00
|
|
|
titre = db.Column(db.Text(), nullable=False)
|
2024-08-11 23:24:40 +02:00
|
|
|
# nb max d'inscriptions (non DEM), null si illimité:
|
|
|
|
capacite_accueil = db.Column(db.Integer, nullable=True)
|
2023-01-09 12:12:31 +01:00
|
|
|
date_debut = db.Column(db.Date(), nullable=False)
|
2024-02-08 16:23:14 +01:00
|
|
|
date_fin = db.Column(db.Date(), nullable=False) # jour inclus
|
2023-11-06 22:05:38 +01:00
|
|
|
edt_id: str | None = db.Column(db.Text(), index=True, nullable=True)
|
|
|
|
"identifiant emplois du temps (unicité non imposée)"
|
2023-01-13 23:23:18 +01:00
|
|
|
etat = db.Column(db.Boolean(), nullable=False, default=True, server_default="true")
|
|
|
|
"False si verrouillé"
|
2021-08-14 18:54:32 +02:00
|
|
|
modalite = db.Column(
|
|
|
|
db.String(SHORT_STR_LEN), db.ForeignKey("notes_form_modalites.modalite")
|
2023-01-24 12:12:24 +01:00
|
|
|
)
|
|
|
|
"Modalité de formation: 'FI', 'FAP', 'FC', ..."
|
2021-08-10 00:23:30 +02:00
|
|
|
gestion_compensation = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"gestion compensation sem DUT (inutilisé en APC)"
|
2021-08-10 00:23:30 +02:00
|
|
|
bul_hide_xml = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
2024-03-19 18:22:02 +01:00
|
|
|
"ne publie pas le bulletin sur l'API"
|
2021-09-16 22:24:08 +02:00
|
|
|
block_moyennes = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"Bloque le calcul des moyennes (générale et d'UE)"
|
2022-11-01 17:39:18 +01:00
|
|
|
block_moyenne_generale = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
2023-01-13 23:50:24 +01:00
|
|
|
"Si vrai, la moyenne générale indicative BUT n'est pas calculée"
|
2024-02-25 16:58:59 +01:00
|
|
|
mode_calcul_moyennes = db.Column(
|
|
|
|
db.Integer, nullable=False, default=0, server_default="0"
|
|
|
|
)
|
|
|
|
"pour usage futur"
|
2021-08-10 00:23:30 +02:00
|
|
|
gestion_semestrielle = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"Semestres décalés (pour gestion jurys DUT, pas implémenté ou utile en BUT)"
|
2021-08-10 00:23:30 +02:00
|
|
|
bul_bgcolor = db.Column(
|
2023-01-09 12:12:31 +01:00
|
|
|
db.String(SHORT_STR_LEN),
|
|
|
|
default="white",
|
|
|
|
server_default="white",
|
|
|
|
nullable=False,
|
2021-08-10 00:23:30 +02:00
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"couleur fond bulletins HTML"
|
2021-08-10 00:23:30 +02:00
|
|
|
resp_can_edit = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"autorise resp. à modifier le formsemestre"
|
2021-08-10 00:23:30 +02:00
|
|
|
resp_can_change_ens = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=True, server_default="true"
|
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"autorise resp. a modifier slt les enseignants"
|
2021-08-10 00:23:30 +02:00
|
|
|
ens_can_edit_eval = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="False"
|
|
|
|
)
|
2023-01-24 12:12:24 +01:00
|
|
|
"autorise les enseignants à créer des évals dans leurs modimpls"
|
2021-08-14 18:54:32 +02:00
|
|
|
elt_sem_apo = db.Column(db.Text()) # peut être fort long !
|
2024-06-24 03:37:40 +02:00
|
|
|
"code element semestre Apogée, eg 'VRTW1' ou 'V2INCS4,V2INLS4,...'"
|
2021-08-14 18:54:32 +02:00
|
|
|
elt_annee_apo = db.Column(db.Text())
|
2023-01-24 12:12:24 +01:00
|
|
|
"code element annee Apogee, eg 'VRT1A' ou 'V2INLA,V2INCA,...'"
|
2024-06-24 03:37:40 +02:00
|
|
|
elt_passage_apo = db.Column(db.Text())
|
|
|
|
"code element passage Apogée"
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2023-05-15 23:39:08 +02:00
|
|
|
# Data pour groups_auto_assignment
|
|
|
|
# (ce champ est utilisé uniquement via l'API par le front js)
|
|
|
|
groups_auto_assignment_data = db.Column(db.LargeBinary(), nullable=True)
|
|
|
|
|
2021-10-16 19:19:07 +02:00
|
|
|
# Relations:
|
2021-08-07 15:20:30 +02:00
|
|
|
etapes = db.relationship(
|
2024-10-19 23:52:35 +02:00
|
|
|
"FormSemestreEtape", cascade="all,delete-orphan", backref="formsemestre"
|
2021-10-16 19:19:07 +02:00
|
|
|
)
|
2021-12-24 00:08:25 +01:00
|
|
|
modimpls = db.relationship(
|
|
|
|
"ModuleImpl",
|
|
|
|
backref="formsemestre",
|
|
|
|
lazy="dynamic",
|
2023-01-12 12:52:32 +01:00
|
|
|
cascade="all, delete-orphan",
|
2021-12-24 00:08:25 +01:00
|
|
|
)
|
2024-08-11 21:39:43 +02:00
|
|
|
description = db.relationship(
|
|
|
|
"FormSemestreDescription",
|
|
|
|
back_populates="formsemestre",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
uselist=False,
|
|
|
|
)
|
2021-11-28 16:31:33 +01:00
|
|
|
etuds = db.relationship(
|
|
|
|
"Identite",
|
|
|
|
secondary="notes_formsemestre_inscription",
|
|
|
|
viewonly=True,
|
|
|
|
lazy="dynamic",
|
|
|
|
)
|
2021-12-04 21:04:09 +01:00
|
|
|
responsables = db.relationship(
|
|
|
|
"User",
|
|
|
|
secondary="notes_formsemestre_responsables",
|
|
|
|
lazy=True,
|
|
|
|
backref=db.backref("formsemestres", lazy=True),
|
2023-09-11 17:58:12 +02:00
|
|
|
order_by=func.upper(User.nom),
|
2021-12-04 21:04:09 +01:00
|
|
|
)
|
2022-02-17 18:13:04 +01:00
|
|
|
partitions = db.relationship(
|
|
|
|
"Partition",
|
|
|
|
backref=db.backref("formsemestre", lazy=True),
|
|
|
|
lazy="dynamic",
|
2022-08-31 19:14:21 +02:00
|
|
|
order_by="Partition.numero",
|
2022-02-17 18:13:04 +01:00
|
|
|
)
|
2021-08-27 22:16:10 +02:00
|
|
|
# Ancien id ScoDoc7 pour les migrations de bases anciennes
|
2021-11-01 15:16:51 +01:00
|
|
|
# ne pas utiliser après migrate_scodoc7_dept_archives
|
2021-08-27 22:16:10 +02:00
|
|
|
scodoc7_id = db.Column(db.Text(), nullable=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
# BUT
|
|
|
|
parcours = db.relationship(
|
|
|
|
"ApcParcours",
|
|
|
|
secondary=parcours_formsemestre,
|
|
|
|
lazy="subquery",
|
|
|
|
backref=db.backref("formsemestres", lazy=True),
|
2023-04-11 23:56:50 +02:00
|
|
|
order_by=(ApcParcours.numero, ApcParcours.code),
|
2022-07-05 16:09:26 +02:00
|
|
|
)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(FormSemestre, self).__init__(**kwargs)
|
|
|
|
if self.modalite is None:
|
2021-11-12 22:17:46 +01:00
|
|
|
self.modalite = FormationModalite.DEFAULT_MODALITE
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2022-01-25 10:45:13 +01:00
|
|
|
def __repr__(self):
|
2022-11-24 00:11:59 +01:00
|
|
|
return f"<{self.__class__.__name__} {self.id} {self.titre_annee()}>"
|
2022-01-25 10:45:13 +01:00
|
|
|
|
2023-06-30 17:26:41 +02:00
|
|
|
def html_link_status(self, label=None, title=None) -> str:
|
2023-06-18 09:37:13 +02:00
|
|
|
"html link to status page"
|
|
|
|
return f"""<a class="stdlink" href="{
|
2023-10-18 15:22:48 +02:00
|
|
|
url_for("notes.formsemestre_status", scodoc_dept=self.departement.acronym,
|
2023-06-18 09:37:13 +02:00
|
|
|
formsemestre_id=self.id,)
|
2023-06-30 17:26:41 +02:00
|
|
|
}" title="{title or ''}">{label or self.titre_mois()}</a>
|
2023-06-18 09:37:13 +02:00
|
|
|
"""
|
|
|
|
|
2023-03-20 11:17:38 +01:00
|
|
|
@classmethod
|
2023-09-25 23:51:38 +02:00
|
|
|
def get_formsemestre(
|
2024-10-04 08:46:09 +02:00
|
|
|
cls, formsemestre_id: int | str, dept_id: int = None, accept_none=False
|
|
|
|
) -> "FormSemestre | None":
|
|
|
|
"""FormSemestre ou 404 (ou None si accept_none), cherche uniquement dans
|
|
|
|
le département spécifié ou le courant (g.scodoc_dept).
|
|
|
|
Si accept_none, return None si l'id est invalide ou ne correspond
|
|
|
|
pas à un formsemestre.
|
|
|
|
"""
|
2023-12-31 22:18:52 +01:00
|
|
|
if not isinstance(formsemestre_id, int):
|
|
|
|
try:
|
|
|
|
formsemestre_id = int(formsemestre_id)
|
|
|
|
except (TypeError, ValueError):
|
2024-10-04 08:46:09 +02:00
|
|
|
if accept_none:
|
|
|
|
return None
|
2023-12-31 22:18:52 +01:00
|
|
|
abort(404, "formsemestre_id invalide")
|
2024-10-04 08:46:09 +02:00
|
|
|
|
|
|
|
dept_id = (
|
|
|
|
dept_id
|
|
|
|
if dept_id is not None
|
|
|
|
else (g.scodoc_dept_id if g.scodoc_dept else None)
|
|
|
|
)
|
|
|
|
|
|
|
|
query = (
|
|
|
|
cls.query.filter_by(id=formsemestre_id)
|
|
|
|
if dept_id is None
|
|
|
|
else cls.query.filter_by(id=formsemestre_id, dept_id=dept_id)
|
|
|
|
)
|
|
|
|
return query.first() if accept_none else query.first_or_404()
|
2023-03-20 11:17:38 +01:00
|
|
|
|
2024-06-18 01:21:33 +02:00
|
|
|
@classmethod
|
|
|
|
def create_formsemestre(cls, args: dict, silent=False) -> "FormSemestre":
|
|
|
|
"""Création d'un formsemestre, avec toutes les valeurs par défaut
|
|
|
|
et notification (sauf si silent).
|
|
|
|
Crée la partition par défaut.
|
|
|
|
"""
|
|
|
|
# was sco_formsemestre.do_formsemestre_create
|
|
|
|
if "dept_id" not in args:
|
|
|
|
args["dept_id"] = g.scodoc_dept_id
|
|
|
|
formsemestre: "FormSemestre" = cls.create_from_dict(args)
|
|
|
|
db.session.flush()
|
2024-10-19 23:52:35 +02:00
|
|
|
for etape in args.get("etapes") or []:
|
2024-06-18 01:21:33 +02:00
|
|
|
formsemestre.add_etape(etape)
|
|
|
|
db.session.commit()
|
|
|
|
# create default partition
|
|
|
|
partition = Partition(
|
|
|
|
formsemestre=formsemestre, partition_name=None, numero=1000000
|
|
|
|
)
|
|
|
|
db.session.add(partition)
|
|
|
|
partition.create_group(default=True)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
if not silent:
|
|
|
|
url = url_for(
|
|
|
|
"notes.formsemestre_status",
|
|
|
|
scodoc_dept=formsemestre.departement.acronym,
|
|
|
|
formsemestre_id=formsemestre.id,
|
|
|
|
)
|
|
|
|
ScolarNews.add(
|
|
|
|
typ=ScolarNews.NEWS_SEM,
|
|
|
|
text=f"""Création du semestre <a href="{url}">{formsemestre.titre}</a>""",
|
|
|
|
url=url,
|
|
|
|
max_frequency=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
return formsemestre
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def convert_dict_fields(cls, args: dict) -> dict:
|
|
|
|
"""Convert fields in the given dict.
|
|
|
|
args: dict with args in application.
|
|
|
|
returns: dict to store in model's db.
|
|
|
|
"""
|
|
|
|
if "date_debut" in args:
|
|
|
|
args["date_debut"] = scu.convert_fr_date(args["date_debut"])
|
|
|
|
if "date_fin" in args:
|
2024-07-04 00:34:50 +02:00
|
|
|
args["date_fin"] = scu.convert_fr_date(args["date_fin"])
|
2024-06-18 01:21:33 +02:00
|
|
|
if "etat" in args:
|
2024-10-19 23:52:35 +02:00
|
|
|
if args["etat"] is None:
|
|
|
|
del args["etat"]
|
|
|
|
else:
|
|
|
|
args["etat"] = bool(args["etat"])
|
2024-06-18 01:21:33 +02:00
|
|
|
if "bul_bgcolor" in args:
|
|
|
|
args["bul_bgcolor"] = args.get("bul_bgcolor") or "white"
|
|
|
|
if "titre" in args:
|
|
|
|
args["titre"] = args.get("titre") or "sans titre"
|
2024-10-19 23:52:35 +02:00
|
|
|
if "capacite_accueil" in args: # peut être un nombre, "" ou None
|
|
|
|
try:
|
|
|
|
args["capacite_accueil"] = (
|
|
|
|
int(args["capacite_accueil"])
|
|
|
|
if args["capacite_accueil"] not in ("", None)
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("capacite_accueil invalide") from exc
|
|
|
|
if "responsables" in args: # peut être liste d'uid ou de user_name ou de User
|
|
|
|
resp_users = [User.get_user(u) for u in args["responsables"]]
|
|
|
|
args["responsables"] = [u for u in resp_users if u is not None]
|
2024-06-18 01:21:33 +02:00
|
|
|
return args
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def filter_model_attributes(cls, data: dict, excluded: set[str] = None) -> dict:
|
|
|
|
"""Returns a copy of dict with only the keys belonging to the Model and not in excluded.
|
|
|
|
Add 'etapes' to excluded."""
|
|
|
|
# on ne peut pas affecter directement etapes
|
|
|
|
return super().filter_model_attributes(data, (excluded or set()) | {"etapes"})
|
|
|
|
|
2023-01-14 18:01:54 +01:00
|
|
|
def sort_key(self) -> tuple:
|
2024-03-26 14:17:42 +01:00
|
|
|
"""clé pour tris par ordre de date_debut, le plus ancien en tête
|
2023-01-14 18:01:54 +01:00
|
|
|
(pour avoir le plus récent d'abord, sort avec reverse=True)"""
|
|
|
|
return (self.date_debut, self.semestre_id)
|
|
|
|
|
2022-07-21 14:21:06 +02:00
|
|
|
def to_dict(self, convert_objects=False) -> dict:
|
|
|
|
"""dict (compatible ScoDoc7).
|
|
|
|
If convert_objects, convert all attributes to native types
|
|
|
|
(suitable jor json encoding).
|
|
|
|
"""
|
2021-12-04 21:04:09 +01:00
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("_sa_instance_state", None)
|
2023-09-10 19:46:50 +02:00
|
|
|
d.pop("groups_auto_assignment_data", None)
|
2021-12-04 21:04:09 +01:00
|
|
|
# ScoDoc7 output_formators: (backward compat)
|
|
|
|
d["formsemestre_id"] = self.id
|
2022-02-13 23:53:11 +01:00
|
|
|
d["titre_num"] = self.titre_num()
|
2022-01-16 23:47:52 +01:00
|
|
|
if self.date_debut:
|
2024-04-02 23:37:23 +02:00
|
|
|
d["date_debut"] = self.date_debut.strftime(scu.DATE_FMT)
|
2022-01-16 23:47:52 +01:00
|
|
|
d["date_debut_iso"] = self.date_debut.isoformat()
|
|
|
|
else:
|
|
|
|
d["date_debut"] = d["date_debut_iso"] = ""
|
|
|
|
if self.date_fin:
|
2024-04-02 23:37:23 +02:00
|
|
|
d["date_fin"] = self.date_fin.strftime(scu.DATE_FMT)
|
2022-01-16 23:47:52 +01:00
|
|
|
d["date_fin_iso"] = self.date_fin.isoformat()
|
|
|
|
else:
|
|
|
|
d["date_fin"] = d["date_fin_iso"] = ""
|
2021-12-04 21:04:09 +01:00
|
|
|
d["responsables"] = [u.id for u in self.responsables]
|
2022-05-09 16:26:23 +02:00
|
|
|
d["titre_formation"] = self.titre_formation()
|
2023-05-11 14:01:23 +02:00
|
|
|
if convert_objects: # pour API
|
2022-12-17 14:05:13 +01:00
|
|
|
d["parcours"] = [p.to_dict() for p in self.get_parcours_apc()]
|
2022-07-27 17:42:58 +02:00
|
|
|
d["departement"] = self.departement.to_dict()
|
|
|
|
d["formation"] = self.formation.to_dict()
|
|
|
|
d["etape_apo"] = self.etapes_apo_str()
|
2023-05-11 14:01:23 +02:00
|
|
|
else:
|
|
|
|
# Converti les étapes Apogee sous forme d'ApoEtapeVDI (compat scodoc7)
|
|
|
|
d["etapes"] = [e.as_apovdi() for e in self.etapes]
|
2022-02-09 00:36:50 +01:00
|
|
|
return d
|
2022-01-16 23:47:52 +01:00
|
|
|
|
2022-05-04 16:28:34 +02:00
|
|
|
def to_dict_api(self):
|
|
|
|
"""
|
2024-03-21 12:06:34 +01:00
|
|
|
Un dict avec les informations sur le semestre destinées à l'api
|
2022-05-04 16:28:34 +02:00
|
|
|
"""
|
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("_sa_instance_state", None)
|
2023-09-10 19:46:50 +02:00
|
|
|
d.pop("groups_auto_assignment_data", None)
|
2022-08-03 21:51:45 +02:00
|
|
|
d["annee_scolaire"] = self.annee_scolaire()
|
2024-03-19 18:22:02 +01:00
|
|
|
d["bul_hide_xml"] = self.bul_hide_xml
|
2022-05-04 16:28:34 +02:00
|
|
|
if self.date_debut:
|
2024-04-02 23:37:23 +02:00
|
|
|
d["date_debut"] = self.date_debut.strftime(scu.DATE_FMT)
|
2022-05-04 16:28:34 +02:00
|
|
|
d["date_debut_iso"] = self.date_debut.isoformat()
|
|
|
|
else:
|
|
|
|
d["date_debut"] = d["date_debut_iso"] = ""
|
|
|
|
if self.date_fin:
|
2024-04-02 23:37:23 +02:00
|
|
|
d["date_fin"] = self.date_fin.strftime(scu.DATE_FMT)
|
2022-05-04 16:28:34 +02:00
|
|
|
d["date_fin_iso"] = self.date_fin.isoformat()
|
|
|
|
else:
|
|
|
|
d["date_fin"] = d["date_fin_iso"] = ""
|
2022-07-27 17:42:58 +02:00
|
|
|
d["departement"] = self.departement.to_dict()
|
2022-07-22 21:22:06 +02:00
|
|
|
d["etape_apo"] = self.etapes_apo_str()
|
|
|
|
d["formsemestre_id"] = self.id
|
2022-07-27 17:42:58 +02:00
|
|
|
d["formation"] = self.formation.to_dict()
|
2022-12-17 14:05:13 +01:00
|
|
|
d["parcours"] = [p.to_dict() for p in self.get_parcours_apc()]
|
2022-05-04 16:28:34 +02:00
|
|
|
d["responsables"] = [u.id for u in self.responsables]
|
|
|
|
d["titre_court"] = self.formation.acronyme
|
2022-12-19 00:26:17 +01:00
|
|
|
d["titre_formation"] = self.titre_formation()
|
2022-07-22 21:22:06 +02:00
|
|
|
d["titre_num"] = self.titre_num()
|
2022-07-20 08:19:24 +02:00
|
|
|
d["session_id"] = self.session_id()
|
2022-05-04 16:28:34 +02:00
|
|
|
return d
|
|
|
|
|
2023-11-11 18:13:18 +01:00
|
|
|
def get_default_group(self) -> GroupDescr:
|
|
|
|
"""default ('tous') group.
|
|
|
|
Le groupe par défaut contient tous les étudiants et existe toujours.
|
|
|
|
C'est l'unique groupe de la partition sans nom.
|
|
|
|
"""
|
|
|
|
default_partition = self.partitions.filter_by(partition_name=None).first()
|
|
|
|
if default_partition:
|
|
|
|
return default_partition.groups.first()
|
|
|
|
raise ScoValueError("Le semestre n'a pas de groupe par défaut")
|
|
|
|
|
2023-11-19 22:35:04 +01:00
|
|
|
def get_edt_ids(self) -> list[str]:
|
2024-01-03 14:43:26 +01:00
|
|
|
"""Les ids pour l'emploi du temps: à défaut, les codes étape Apogée.
|
|
|
|
Les edt_id de formsemestres ne sont pas normalisés afin de contrôler
|
|
|
|
précisément l'accès au fichier ics.
|
|
|
|
"""
|
2023-11-11 18:13:18 +01:00
|
|
|
return (
|
2023-11-19 22:35:04 +01:00
|
|
|
scu.split_id(self.edt_id)
|
|
|
|
or [e.etape_apo.strip() for e in self.etapes if e.etape_apo]
|
|
|
|
or []
|
2023-11-11 18:13:18 +01:00
|
|
|
)
|
|
|
|
|
2022-02-09 00:36:50 +01:00
|
|
|
def get_infos_dict(self) -> dict:
|
|
|
|
"""Un dict avec des informations sur le semestre
|
|
|
|
pour les bulletins et autres templates
|
|
|
|
(contenu compatible scodoc7 / anciens templates)
|
|
|
|
"""
|
|
|
|
d = self.to_dict()
|
|
|
|
d["anneescolaire"] = self.annee_scolaire_str()
|
|
|
|
d["annee_debut"] = str(self.date_debut.year)
|
|
|
|
d["annee"] = d["annee_debut"]
|
|
|
|
d["annee_fin"] = str(self.date_fin.year)
|
2022-02-10 22:35:55 +01:00
|
|
|
if d["annee_fin"] != d["annee_debut"]:
|
|
|
|
d["annee"] += "-" + str(d["annee_fin"])
|
2022-02-09 00:36:50 +01:00
|
|
|
d["mois_debut_ord"] = self.date_debut.month
|
|
|
|
d["mois_fin_ord"] = self.date_fin.month
|
|
|
|
# La période: considère comme "S1" (ou S3) les débuts en aout-sept-octobre
|
2022-11-13 14:55:18 +01:00
|
|
|
# devrait sans doute pouvoir etre changé... XXX PIVOT
|
|
|
|
d["periode"] = self.periode()
|
2022-02-09 00:36:50 +01:00
|
|
|
if self.date_debut.month >= 8 and self.date_debut.month <= 10:
|
|
|
|
d["periode"] = 1 # typiquement, début en septembre: S1, S3...
|
|
|
|
else:
|
|
|
|
d["periode"] = 2 # typiquement, début en février: S2, S4...
|
2022-02-10 22:35:55 +01:00
|
|
|
d["titreannee"] = self.titre_annee()
|
2022-03-07 21:49:11 +01:00
|
|
|
d["mois_debut"] = self.mois_debut()
|
|
|
|
d["mois_fin"] = self.mois_fin()
|
2022-02-09 00:36:50 +01:00
|
|
|
d["titremois"] = "%s %s (%s - %s)" % (
|
|
|
|
d["titre_num"],
|
|
|
|
self.modalite or "",
|
|
|
|
d["mois_debut"],
|
|
|
|
d["mois_fin"],
|
|
|
|
)
|
|
|
|
d["session_id"] = self.session_id()
|
|
|
|
d["etapes"] = self.etapes_apo_vdi()
|
|
|
|
d["etapes_apo_str"] = self.etapes_apo_str()
|
2021-12-04 21:04:09 +01:00
|
|
|
return d
|
|
|
|
|
2023-02-21 21:34:38 +01:00
|
|
|
def flip_lock(self):
|
|
|
|
"""Flip etat (lock)"""
|
|
|
|
self.etat = not self.etat
|
|
|
|
db.session.add(self)
|
|
|
|
|
2022-12-17 13:43:47 +01:00
|
|
|
def get_parcours_apc(self) -> list[ApcParcours]:
|
|
|
|
"""Liste des parcours proposés par ce semestre.
|
|
|
|
Si aucun n'est coché et qu'il y a un référentiel, tous ceux du référentiel.
|
|
|
|
"""
|
2022-12-19 00:30:47 +01:00
|
|
|
r = self.parcours or (
|
2022-12-17 13:43:47 +01:00
|
|
|
self.formation.referentiel_competence
|
|
|
|
and self.formation.referentiel_competence.parcours
|
|
|
|
)
|
2022-12-19 00:30:47 +01:00
|
|
|
return r or []
|
2022-12-17 13:43:47 +01:00
|
|
|
|
2023-04-03 17:46:31 +02:00
|
|
|
def get_ues(self, with_sport=False) -> list[UniteEns]:
|
2021-12-20 20:38:21 +01:00
|
|
|
"""UE des modules de ce semestre, triées par numéro.
|
2021-11-17 10:28:51 +01:00
|
|
|
- Formations classiques: les UEs auxquelles appartiennent
|
|
|
|
les modules mis en place dans ce semestre.
|
2022-12-08 18:49:05 +01:00
|
|
|
- Formations APC / BUT: les UEs de la formation qui
|
2023-04-03 17:46:31 +02:00
|
|
|
- ont le même numéro de semestre que ce formsemestre;
|
|
|
|
- et sont associées à l'un des parcours de ce formsemestre
|
|
|
|
(ou à aucun, donc tronc commun).
|
2021-11-17 10:28:51 +01:00
|
|
|
"""
|
2023-07-24 16:48:41 +02:00
|
|
|
# per-request caching
|
|
|
|
key = (self.id, with_sport)
|
|
|
|
_cache = getattr(g, "_formsemestre_get_ues_cache", None)
|
|
|
|
if _cache:
|
|
|
|
result = _cache.get(key, False)
|
|
|
|
if result is not False:
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
g._formsemestre_get_ues_cache = {}
|
|
|
|
_cache = g._formsemestre_get_ues_cache
|
|
|
|
|
2023-04-03 17:46:31 +02:00
|
|
|
formation: Formation = self.formation
|
|
|
|
if formation.is_apc():
|
2023-05-15 11:05:51 +02:00
|
|
|
# UEs de tronc commun (sans parcours indiqué)
|
2023-04-03 17:46:31 +02:00
|
|
|
sem_ues = {
|
|
|
|
ue.id: ue
|
|
|
|
for ue in formation.query_ues_parcour(
|
|
|
|
None, with_sport=with_sport
|
|
|
|
).filter(UniteEns.semestre_idx == self.semestre_id)
|
|
|
|
}
|
2023-05-15 11:05:51 +02:00
|
|
|
# Ajoute les UE de parcours
|
2023-04-03 17:46:31 +02:00
|
|
|
for parcour in self.parcours:
|
|
|
|
sem_ues.update(
|
|
|
|
{
|
|
|
|
ue.id: ue
|
|
|
|
for ue in formation.query_ues_parcour(
|
|
|
|
parcour, with_sport=with_sport
|
|
|
|
).filter(UniteEns.semestre_idx == self.semestre_id)
|
|
|
|
}
|
2022-12-17 13:18:10 +01:00
|
|
|
)
|
2023-07-24 16:48:41 +02:00
|
|
|
ues = sorted(sem_ues.values(), key=attrgetter("numero", "acronyme"))
|
2021-11-17 10:28:51 +01:00
|
|
|
else:
|
|
|
|
sem_ues = db.session.query(UniteEns).filter(
|
|
|
|
ModuleImpl.formsemestre_id == self.id,
|
|
|
|
Module.id == ModuleImpl.module_id,
|
|
|
|
UniteEns.id == Module.ue_id,
|
|
|
|
)
|
2023-04-03 17:46:31 +02:00
|
|
|
if not with_sport:
|
|
|
|
sem_ues = sem_ues.filter(UniteEns.type != codes_cursus.UE_SPORT)
|
2024-09-08 23:52:32 +02:00
|
|
|
ues = sem_ues.order_by(UniteEns.numero, UniteEns.acronyme).all()
|
2023-07-24 16:48:41 +02:00
|
|
|
_cache[key] = ues
|
|
|
|
return ues
|
2022-07-05 16:09:26 +02:00
|
|
|
|
2023-12-29 13:58:18 +01:00
|
|
|
@classmethod
|
2023-12-31 22:18:52 +01:00
|
|
|
def get_user_formsemestres_annee_by_dept(
|
2023-12-29 13:58:18 +01:00
|
|
|
cls, user: User
|
2023-12-31 22:18:52 +01:00
|
|
|
) -> tuple[
|
|
|
|
defaultdict[int, list["FormSemestre"]], defaultdict[int, list[ModuleImpl]]
|
|
|
|
]:
|
2023-12-29 13:58:18 +01:00
|
|
|
"""Liste des formsemestres de l'année scolaire
|
|
|
|
dans lesquels user intervient (comme resp., resp. de module ou enseignant),
|
|
|
|
ainsi que la liste des modimpls concernés dans chaque formsemestre
|
|
|
|
Attention: les semestres et modimpls peuvent être de différents départements !
|
2023-12-31 22:18:52 +01:00
|
|
|
Résultat:
|
|
|
|
{ dept_id : [ formsemestre, ... ] },
|
|
|
|
{ formsemestre_id : [ modimpl, ... ]}
|
2023-12-29 13:58:18 +01:00
|
|
|
"""
|
|
|
|
debut_annee_scolaire = scu.date_debut_annee_scolaire()
|
|
|
|
fin_annee_scolaire = scu.date_fin_annee_scolaire()
|
|
|
|
|
|
|
|
query = FormSemestre.query.filter(
|
|
|
|
FormSemestre.date_fin >= debut_annee_scolaire,
|
|
|
|
FormSemestre.date_debut < fin_annee_scolaire,
|
|
|
|
)
|
|
|
|
# responsable ?
|
|
|
|
formsemestres_resp = query.join(notes_formsemestre_responsables).filter_by(
|
|
|
|
responsable_id=user.id
|
|
|
|
)
|
|
|
|
# Responsable d'un modimpl ?
|
|
|
|
modimpls_resp = (
|
|
|
|
ModuleImpl.query.filter_by(responsable_id=user.id)
|
|
|
|
.join(FormSemestre)
|
|
|
|
.filter(
|
|
|
|
FormSemestre.date_fin >= debut_annee_scolaire,
|
|
|
|
FormSemestre.date_debut < fin_annee_scolaire,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# Enseignant dans un modimpl ?
|
|
|
|
modimpls_ens = (
|
|
|
|
ModuleImpl.query.join(notes_modules_enseignants)
|
|
|
|
.filter_by(ens_id=user.id)
|
|
|
|
.join(FormSemestre)
|
|
|
|
.filter(
|
|
|
|
FormSemestre.date_fin >= debut_annee_scolaire,
|
|
|
|
FormSemestre.date_debut < fin_annee_scolaire,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# Liste les modimpls, uniques
|
|
|
|
modimpls = modimpls_resp.all()
|
|
|
|
ids = {modimpl.id for modimpl in modimpls}
|
|
|
|
for modimpl in modimpls_ens:
|
|
|
|
if modimpl.id not in ids:
|
|
|
|
modimpls.append(modimpl)
|
|
|
|
ids.add(modimpl.id)
|
|
|
|
# Liste les formsemestres et modimpls associés
|
|
|
|
modimpls_by_formsemestre = defaultdict(lambda: [])
|
|
|
|
formsemestres = formsemestres_resp.all()
|
|
|
|
ids = {formsemestre.id for formsemestre in formsemestres}
|
|
|
|
for modimpl in chain(modimpls_resp, modimpls_ens):
|
|
|
|
if modimpl.formsemestre_id not in ids:
|
|
|
|
formsemestres.append(modimpl.formsemestre)
|
|
|
|
ids.add(modimpl.formsemestre_id)
|
|
|
|
modimpls_by_formsemestre[modimpl.formsemestre_id].append(modimpl)
|
2023-12-31 22:18:52 +01:00
|
|
|
# Tris et organisation par département
|
|
|
|
formsemestres_by_dept = defaultdict(lambda: [])
|
2023-12-29 13:58:18 +01:00
|
|
|
formsemestres.sort(key=lambda x: (x.departement.acronym,) + x.sort_key())
|
|
|
|
for formsemestre in formsemestres:
|
2023-12-31 22:18:52 +01:00
|
|
|
formsemestres_by_dept[formsemestre.dept_id].append(formsemestre)
|
2023-12-29 13:58:18 +01:00
|
|
|
modimpls = modimpls_by_formsemestre[formsemestre.id]
|
|
|
|
if formsemestre.formation.is_apc():
|
|
|
|
key = lambda x: x.module.sort_key_apc()
|
|
|
|
else:
|
|
|
|
key = lambda x: x.module.sort_key()
|
|
|
|
modimpls.sort(key=key)
|
|
|
|
|
2023-12-31 22:18:52 +01:00
|
|
|
return formsemestres_by_dept, modimpls_by_formsemestre
|
2023-12-29 13:58:18 +01:00
|
|
|
|
2023-08-25 17:58:57 +02:00
|
|
|
def get_evaluations(self) -> list[Evaluation]:
|
|
|
|
"Liste de toutes les évaluations du semestre, triées par module/numero"
|
|
|
|
return (
|
|
|
|
Evaluation.query.join(ModuleImpl)
|
|
|
|
.filter_by(formsemestre_id=self.id)
|
|
|
|
.join(Module)
|
|
|
|
.order_by(
|
|
|
|
Module.numero,
|
|
|
|
Module.code,
|
|
|
|
Evaluation.numero,
|
2023-12-10 20:59:32 +01:00
|
|
|
Evaluation.date_debut,
|
2023-08-25 17:58:57 +02:00
|
|
|
)
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
|
2022-01-25 10:45:13 +01:00
|
|
|
@cached_property
|
|
|
|
def modimpls_sorted(self) -> list[ModuleImpl]:
|
2022-02-06 16:09:17 +01:00
|
|
|
"""Liste des modimpls du semestre (y compris bonus)
|
2022-01-25 10:45:13 +01:00
|
|
|
- triée par type/numéro/code en APC
|
|
|
|
- triée par numéros d'UE/matières/modules pour les formations standard.
|
2023-12-15 01:07:08 +01:00
|
|
|
Hors APC, élimine les modules de type ressources et SAEs.
|
2022-01-25 10:45:13 +01:00
|
|
|
"""
|
|
|
|
modimpls = self.modimpls.all()
|
|
|
|
if self.formation.is_apc():
|
|
|
|
modimpls.sort(
|
2022-03-02 16:31:42 +01:00
|
|
|
key=lambda m: (
|
2023-01-14 18:01:54 +01:00
|
|
|
m.module.module_type or 0, # ressources (2) avant SAEs (3)
|
2022-03-02 16:31:42 +01:00
|
|
|
m.module.numero or 0,
|
|
|
|
m.module.code or 0,
|
|
|
|
)
|
2022-01-25 10:45:13 +01:00
|
|
|
)
|
|
|
|
else:
|
2023-12-15 01:07:08 +01:00
|
|
|
modimpls = [
|
|
|
|
mi
|
|
|
|
for mi in modimpls
|
|
|
|
if (
|
|
|
|
mi.module.module_type
|
|
|
|
not in (scu.ModuleType.RESSOURCE, scu.ModuleType.SAE)
|
|
|
|
)
|
|
|
|
]
|
2022-01-25 10:45:13 +01:00
|
|
|
modimpls.sort(
|
|
|
|
key=lambda m: (
|
2022-02-02 09:51:28 +01:00
|
|
|
m.module.ue.numero or 0,
|
|
|
|
m.module.matiere.numero or 0,
|
|
|
|
m.module.numero or 0,
|
|
|
|
m.module.code or "",
|
2022-01-25 10:45:13 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
return modimpls
|
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
def modimpls_parcours(self, parcours: ApcParcours) -> list[ModuleImpl]:
|
|
|
|
"""Liste des modimpls du semestre (sans les bonus (?)) dans le parcours donné.
|
|
|
|
- triée par type/numéro/code ??
|
|
|
|
"""
|
|
|
|
cursor = db.session.execute(
|
|
|
|
text(
|
|
|
|
"""
|
|
|
|
SELECT modimpl.id
|
|
|
|
FROM notes_moduleimpl modimpl, notes_modules mod,
|
|
|
|
parcours_modules pm, parcours_formsemestre pf
|
|
|
|
WHERE modimpl.formsemestre_id = :formsemestre_id
|
|
|
|
AND modimpl.module_id = mod.id
|
|
|
|
AND pm.module_id = mod.id
|
|
|
|
AND pm.parcours_id = pf.parcours_id
|
|
|
|
AND pf.parcours_id = :parcours_id
|
|
|
|
AND pf.formsemestre_id = :formsemestre_id
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
{"formsemestre_id": self.id, "parcours_id": parcours.id},
|
|
|
|
)
|
2023-07-11 06:57:38 +02:00
|
|
|
return [db.session.get(ModuleImpl, modimpl_id) for modimpl_id in cursor]
|
2022-07-05 16:09:26 +02:00
|
|
|
|
2022-02-01 17:42:43 +01:00
|
|
|
def can_be_edited_by(self, user):
|
2022-12-18 03:14:13 +01:00
|
|
|
"""Vrai si user peut modifier ce semestre (est chef ou l'un des responsables)"""
|
2023-09-29 21:17:31 +02:00
|
|
|
if not user.has_permission(Permission.EditFormSemestre): # pas chef
|
2022-02-01 17:42:43 +01:00
|
|
|
if not self.resp_can_edit or user.id not in [
|
|
|
|
resp.id for resp in self.responsables
|
|
|
|
]:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2021-12-04 21:04:09 +01:00
|
|
|
def est_courant(self) -> bool:
|
|
|
|
"""Vrai si la date actuelle (now) est dans le semestre
|
|
|
|
(les dates de début et fin sont incluses)
|
|
|
|
"""
|
|
|
|
today = datetime.date.today()
|
2022-11-13 14:55:18 +01:00
|
|
|
return self.date_debut <= today <= self.date_fin
|
2021-12-04 21:04:09 +01:00
|
|
|
|
2021-12-29 14:41:33 +01:00
|
|
|
def contient_periode(self, date_debut, date_fin) -> bool:
|
|
|
|
"""Vrai si l'intervalle [date_debut, date_fin] est
|
|
|
|
inclus dans le semestre.
|
2021-12-23 19:28:25 +01:00
|
|
|
(les dates de début et fin sont incluses)
|
|
|
|
"""
|
|
|
|
return (self.date_debut <= date_debut) and (date_fin <= self.date_fin)
|
|
|
|
|
2022-01-07 15:11:24 +01:00
|
|
|
def est_sur_une_annee(self):
|
|
|
|
"""Test si sem est entièrement sur la même année scolaire.
|
|
|
|
(ce n'est pas obligatoire mais si ce n'est pas le
|
|
|
|
cas les exports Apogée risquent de mal fonctionner)
|
2022-11-09 12:50:10 +01:00
|
|
|
Pivot au 1er août par défaut.
|
2022-01-07 15:11:24 +01:00
|
|
|
"""
|
|
|
|
if self.date_debut > self.date_fin:
|
2022-11-13 14:55:18 +01:00
|
|
|
flash(f"Dates début/fin inversées pour le semestre {self.titre_annee()}")
|
2022-01-07 15:11:24 +01:00
|
|
|
log(f"Warning: semestre {self.id} begins after ending !")
|
|
|
|
annee_debut = self.date_debut.year
|
2022-11-13 14:55:18 +01:00
|
|
|
month_debut_annee = ScoDocSiteConfig.get_month_debut_annee_scolaire()
|
|
|
|
if self.date_debut.month < month_debut_annee:
|
|
|
|
# début sur l'année scolaire précédente (juillet inclus par défaut)
|
2022-01-07 15:11:24 +01:00
|
|
|
annee_debut -= 1
|
|
|
|
annee_fin = self.date_fin.year
|
2022-11-13 14:55:18 +01:00
|
|
|
if self.date_fin.month < (month_debut_annee + 1):
|
|
|
|
# 9 (sept) pour autoriser un début en sept et une fin en août
|
2022-01-07 15:11:24 +01:00
|
|
|
annee_fin -= 1
|
|
|
|
return annee_debut == annee_fin
|
|
|
|
|
2021-12-04 21:04:09 +01:00
|
|
|
def est_decale(self):
|
|
|
|
"""Vrai si semestre "décalé"
|
2022-11-09 12:50:10 +01:00
|
|
|
c'est à dire semestres impairs commençant (par défaut)
|
|
|
|
entre janvier et juin et les pairs entre juillet et décembre.
|
2021-12-04 21:04:09 +01:00
|
|
|
"""
|
|
|
|
if self.semestre_id <= 0:
|
|
|
|
return False # formations sans semestres
|
2022-11-09 12:50:10 +01:00
|
|
|
return (
|
|
|
|
# impair
|
|
|
|
(
|
|
|
|
self.semestre_id % 2
|
2022-11-13 14:55:18 +01:00
|
|
|
and self.date_debut.month < scu.MONTH_DEBUT_ANNEE_SCOLAIRE
|
2022-11-09 12:50:10 +01:00
|
|
|
)
|
|
|
|
or
|
|
|
|
# pair
|
|
|
|
(
|
|
|
|
(not self.semestre_id % 2)
|
2022-11-13 14:55:18 +01:00
|
|
|
and self.date_debut.month >= scu.MONTH_DEBUT_ANNEE_SCOLAIRE
|
2022-11-09 12:50:10 +01:00
|
|
|
)
|
2021-12-04 21:04:09 +01:00
|
|
|
)
|
|
|
|
|
2024-06-09 15:18:03 +02:00
|
|
|
@classmethod
|
|
|
|
def est_in_semestre_scolaire(
|
|
|
|
cls,
|
|
|
|
date_debut: datetime.date,
|
|
|
|
year=False,
|
|
|
|
periode=None,
|
|
|
|
mois_pivot_annee=scu.MONTH_DEBUT_ANNEE_SCOLAIRE,
|
|
|
|
mois_pivot_periode=scu.MONTH_DEBUT_PERIODE2,
|
|
|
|
) -> bool:
|
|
|
|
"""Vrai si la date_debut est dans la période indiquée (1,2,0)
|
|
|
|
du semestre `periode` de l'année scolaire indiquée
|
|
|
|
(ou, à défaut, de celle en cours).
|
|
|
|
|
|
|
|
La période utilise les même conventions que semset["sem_id"];
|
|
|
|
* 1 : première période
|
|
|
|
* 2 : deuxième période
|
|
|
|
* 0 ou période non précisée: annualisé (donc inclut toutes les périodes)
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
if not year:
|
|
|
|
year = scu.annee_scolaire()
|
|
|
|
# n'utilise pas le jour pivot
|
|
|
|
jour_pivot_annee = jour_pivot_periode = 1
|
|
|
|
# calcule l'année universitaire et la période
|
|
|
|
sem_annee, sem_periode = cls.comp_periode(
|
|
|
|
date_debut,
|
|
|
|
mois_pivot_annee,
|
|
|
|
mois_pivot_periode,
|
|
|
|
jour_pivot_annee,
|
|
|
|
jour_pivot_periode,
|
|
|
|
)
|
|
|
|
if periode is None or periode == 0:
|
|
|
|
return sem_annee == year
|
|
|
|
return sem_annee == year and sem_periode == periode
|
|
|
|
|
2023-02-19 02:54:29 +01:00
|
|
|
def est_terminal(self) -> bool:
|
|
|
|
"Vrai si dernier semestre de son cursus (ou formation mono-semestre)"
|
|
|
|
return (self.semestre_id < 0) or (
|
|
|
|
self.semestre_id == self.formation.get_cursus().NB_SEM
|
|
|
|
)
|
|
|
|
|
2022-11-13 14:55:18 +01:00
|
|
|
@classmethod
|
|
|
|
def comp_periode(
|
|
|
|
cls,
|
|
|
|
date_debut: datetime,
|
|
|
|
mois_pivot_annee=scu.MONTH_DEBUT_ANNEE_SCOLAIRE,
|
|
|
|
mois_pivot_periode=scu.MONTH_DEBUT_PERIODE2,
|
|
|
|
jour_pivot_annee=1,
|
|
|
|
jour_pivot_periode=1,
|
2023-11-26 18:28:56 +01:00
|
|
|
) -> tuple[int, int]:
|
2022-11-13 14:55:18 +01:00
|
|
|
"""Calcule la session associée à un formsemestre commençant en date_debut
|
|
|
|
sous la forme (année, période)
|
|
|
|
année: première année de l'année scolaire
|
|
|
|
période = 1 (première période de l'année scolaire, souvent automne)
|
|
|
|
ou 2 (deuxième période de l'année scolaire, souvent printemps)
|
|
|
|
Les quatre derniers paramètres forment les dates pivots pour l'année
|
|
|
|
(1er août par défaut) et pour la période (1er décembre par défaut).
|
|
|
|
|
|
|
|
Les calculs se font à partir de la date de début indiquée.
|
|
|
|
Exemples dans tests/unit/test_periode
|
|
|
|
|
|
|
|
Implémentation:
|
|
|
|
Cas à considérer pour le calcul de la période
|
|
|
|
|
|
|
|
pa < pp -----------------|-------------------|---------------->
|
|
|
|
(A-1, P:2) pa (A, P:1) pp (A, P:2)
|
|
|
|
pp < pa -----------------|-------------------|---------------->
|
|
|
|
(A-1, P:1) pp (A-1, P:2) pa (A, P:1)
|
|
|
|
"""
|
|
|
|
pivot_annee = 100 * mois_pivot_annee + jour_pivot_annee
|
|
|
|
pivot_periode = 100 * mois_pivot_periode + jour_pivot_periode
|
|
|
|
pivot_sem = 100 * date_debut.month + date_debut.day
|
|
|
|
if pivot_sem < pivot_annee:
|
|
|
|
annee = date_debut.year - 1
|
|
|
|
else:
|
|
|
|
annee = date_debut.year
|
|
|
|
if pivot_annee < pivot_periode:
|
|
|
|
if pivot_sem < pivot_annee or pivot_sem >= pivot_periode:
|
|
|
|
periode = 2
|
|
|
|
else:
|
|
|
|
periode = 1
|
|
|
|
else:
|
|
|
|
if pivot_sem < pivot_periode or pivot_sem >= pivot_annee:
|
|
|
|
periode = 1
|
|
|
|
else:
|
|
|
|
periode = 2
|
|
|
|
return annee, periode
|
|
|
|
|
|
|
|
def periode(self) -> int:
|
|
|
|
"""La période:
|
|
|
|
* 1 : première période: automne à Paris
|
|
|
|
* 2 : deuxième période, printemps à Paris
|
|
|
|
"""
|
|
|
|
return FormSemestre.comp_periode(
|
|
|
|
self.date_debut,
|
|
|
|
mois_pivot_annee=ScoDocSiteConfig.get_month_debut_annee_scolaire(),
|
|
|
|
mois_pivot_periode=ScoDocSiteConfig.get_month_debut_periode2(),
|
|
|
|
)
|
|
|
|
|
2023-11-26 18:28:56 +01:00
|
|
|
@classmethod
|
|
|
|
def get_dept_formsemestres_courants(
|
|
|
|
cls, dept: Departement, date_courante: datetime.datetime | None = None
|
2024-10-18 23:37:16 +02:00
|
|
|
) -> Query:
|
2023-11-26 18:28:56 +01:00
|
|
|
"""Liste (query) ordonnée des formsemestres courants, c'est
|
|
|
|
à dire contenant la date courant (si None, la date actuelle)"""
|
2024-01-30 14:18:27 +01:00
|
|
|
date_courante = date_courante or db.func.current_date()
|
2023-11-26 18:28:56 +01:00
|
|
|
# Les semestres en cours de ce département
|
|
|
|
formsemestres = FormSemestre.query.filter(
|
|
|
|
FormSemestre.dept_id == dept.id,
|
|
|
|
FormSemestre.date_debut <= date_courante,
|
|
|
|
FormSemestre.date_fin >= date_courante,
|
|
|
|
)
|
|
|
|
return formsemestres.order_by(
|
|
|
|
FormSemestre.date_debut.desc(),
|
|
|
|
FormSemestre.modalite,
|
|
|
|
FormSemestre.semestre_id,
|
|
|
|
FormSemestre.titre,
|
|
|
|
)
|
|
|
|
|
2024-06-18 01:21:33 +02:00
|
|
|
def etapes_apo_vdi(self) -> list["ApoEtapeVDI"]:
|
2022-02-09 00:36:50 +01:00
|
|
|
"Liste des vdis"
|
|
|
|
# was read_formsemestre_etapes
|
|
|
|
return [e.as_apovdi() for e in self.etapes if e.etape_apo]
|
|
|
|
|
2021-12-04 21:04:09 +01:00
|
|
|
def etapes_apo_str(self) -> str:
|
|
|
|
"""Chaine décrivant les étapes de ce semestre
|
|
|
|
ex: "V1RT, V1RT3, V1RT4"
|
|
|
|
"""
|
|
|
|
if not self.etapes:
|
|
|
|
return ""
|
2022-05-10 10:06:51 +02:00
|
|
|
return ", ".join(sorted([etape.etape_apo for etape in self.etapes if etape]))
|
2021-12-04 21:04:09 +01:00
|
|
|
|
2024-06-18 01:21:33 +02:00
|
|
|
def add_etape(self, etape_apo: str | ApoEtapeVDI):
|
2023-07-01 17:42:04 +02:00
|
|
|
"Ajoute une étape"
|
2024-06-18 01:21:33 +02:00
|
|
|
etape = FormSemestreEtape(formsemestre_id=self.id, etape_apo=str(etape_apo))
|
2023-07-01 17:42:04 +02:00
|
|
|
db.session.add(etape)
|
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
def regroupements_coherents_etud(self) -> list[tuple[UniteEns, UniteEns]]:
|
|
|
|
"""Calcule la liste des regroupements cohérents d'UE impliquant ce
|
|
|
|
formsemestre.
|
|
|
|
Pour une année donnée: l'étudiant est inscrit dans ScoDoc soit dans le semestre
|
|
|
|
impair, soit pair, soit les deux (il est rare mais pas impossible d'avoir une
|
|
|
|
inscription seulement en semestre pair, par exemple suite à un transfert ou un
|
|
|
|
arrêt temporaire du cursus).
|
|
|
|
|
|
|
|
1. Déterminer l'*autre* formsemestre: semestre précédent ou suivant de la même
|
|
|
|
année, formation compatible (même référentiel de compétence) dans lequel
|
|
|
|
l'étudiant est inscrit.
|
|
|
|
|
|
|
|
2. Construire les couples d'UE (regroupements cohérents): apparier les UE qui
|
|
|
|
ont le même `ApcParcoursNiveauCompetence`.
|
|
|
|
"""
|
|
|
|
if not self.formation.is_apc():
|
|
|
|
return []
|
|
|
|
raise NotImplementedError() # XXX
|
|
|
|
|
2021-12-04 21:04:09 +01:00
|
|
|
def responsables_str(self, abbrev_prenom=True) -> str:
|
|
|
|
"""chaîne "J. Dupond, X. Martin"
|
|
|
|
ou "Jacques Dupond, Xavier Martin"
|
|
|
|
"""
|
2022-03-07 21:49:11 +01:00
|
|
|
# was "nomcomplet"
|
2021-12-04 21:04:09 +01:00
|
|
|
if not self.responsables:
|
|
|
|
return ""
|
|
|
|
if abbrev_prenom:
|
|
|
|
return ", ".join([u.get_prenomnom() for u in self.responsables])
|
|
|
|
else:
|
|
|
|
return ", ".join([u.get_nomcomplet() for u in self.responsables])
|
|
|
|
|
2024-07-10 00:53:09 +02:00
|
|
|
def est_responsable(self, user: User) -> bool:
|
2022-03-15 21:50:37 +01:00
|
|
|
"True si l'user est l'un des responsables du semestre"
|
|
|
|
return user.id in [u.id for u in self.responsables]
|
|
|
|
|
2024-07-10 00:53:09 +02:00
|
|
|
def est_chef_or_diretud(self, user: User | None = None) -> bool:
|
2023-02-12 01:13:43 +01:00
|
|
|
"Vrai si utilisateur (par def. current) est admin, chef dept ou responsable du semestre"
|
|
|
|
user = user or current_user
|
2023-09-29 21:17:31 +02:00
|
|
|
return user.has_permission(Permission.EditFormSemestre) or self.est_responsable(
|
2023-02-12 01:13:43 +01:00
|
|
|
user
|
|
|
|
)
|
|
|
|
|
2023-07-08 16:35:32 +02:00
|
|
|
def can_change_groups(self, user: User = None) -> bool:
|
|
|
|
"""Vrai si l'utilisateur (par def. current) peut changer les groupes dans
|
2023-11-13 12:16:10 +01:00
|
|
|
ce semestre: vérifie permission et verrouillage (mais pas si la partition est éditable).
|
2023-07-08 16:35:32 +02:00
|
|
|
"""
|
|
|
|
if not self.etat:
|
|
|
|
return False # semestre verrouillé
|
|
|
|
user = user or current_user
|
2023-09-29 21:17:31 +02:00
|
|
|
if user.has_permission(Permission.EtudChangeGroups):
|
2023-07-08 16:35:32 +02:00
|
|
|
return True # typiquement admin, chef dept
|
|
|
|
return self.est_responsable(user)
|
|
|
|
|
2024-07-10 00:53:09 +02:00
|
|
|
def can_edit_jury(self, user: User | None = None):
|
2023-02-12 01:13:43 +01:00
|
|
|
"""Vrai si utilisateur (par def. current) peut saisir decision de jury
|
|
|
|
dans ce semestre: vérifie permission et verrouillage.
|
|
|
|
"""
|
|
|
|
user = user or current_user
|
|
|
|
return self.etat and self.est_chef_or_diretud(user)
|
|
|
|
|
|
|
|
def can_edit_pv(self, user: User = None):
|
|
|
|
"Vrai si utilisateur (par def. current) peut editer un PV de jury de ce semestre"
|
|
|
|
user = user or current_user
|
2023-09-29 21:17:31 +02:00
|
|
|
# Autorise les secrétariats, repérés via la permission EtudChangeAdr
|
2023-02-12 01:13:43 +01:00
|
|
|
return self.est_chef_or_diretud(user) or user.has_permission(
|
2023-09-29 21:17:31 +02:00
|
|
|
Permission.EtudChangeAdr
|
2023-02-12 01:13:43 +01:00
|
|
|
)
|
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
def annee_scolaire(self) -> int:
|
|
|
|
"""L'année de début de l'année scolaire.
|
2022-11-13 14:55:18 +01:00
|
|
|
Par exemple, 2022 si le semestre va de septembre 2022 à février 2023."""
|
2022-07-05 16:09:26 +02:00
|
|
|
return scu.annee_scolaire_debut(self.date_debut.year, self.date_debut.month)
|
|
|
|
|
2021-12-05 20:21:51 +01:00
|
|
|
def annee_scolaire_str(self):
|
|
|
|
"2021 - 2022"
|
|
|
|
return scu.annee_scolaire_repr(self.date_debut.year, self.date_debut.month)
|
|
|
|
|
2022-03-07 21:49:11 +01:00
|
|
|
def mois_debut(self) -> str:
|
|
|
|
"Oct 2021"
|
|
|
|
return f"{MONTH_NAMES_ABBREV[self.date_debut.month - 1]} {self.date_debut.year}"
|
|
|
|
|
|
|
|
def mois_fin(self) -> str:
|
|
|
|
"Jul 2022"
|
2022-03-14 20:23:56 +01:00
|
|
|
return f"{MONTH_NAMES_ABBREV[self.date_fin.month - 1]} {self.date_fin.year}"
|
2022-03-07 21:49:11 +01:00
|
|
|
|
2021-12-04 21:04:09 +01:00
|
|
|
def session_id(self) -> str:
|
|
|
|
"""identifiant externe de semestre de formation
|
|
|
|
Exemple: RT-DUT-FI-S1-ANNEE
|
|
|
|
|
|
|
|
DEPT-TYPE-MODALITE+-S?|SPECIALITE
|
|
|
|
|
|
|
|
TYPE=DUT|LP*|M*
|
|
|
|
MODALITE=FC|FI|FA (si plusieurs, en inverse alpha)
|
|
|
|
|
|
|
|
SPECIALITE=[A-Z]+ EON,ASSUR, ... (si pas Sn ou SnD)
|
|
|
|
|
|
|
|
ANNEE=annee universitaire de debut (exemple: un S2 de 2013-2014 sera S2-2013)
|
|
|
|
"""
|
2022-05-09 16:26:23 +02:00
|
|
|
prefs = sco_preferences.SemPreferences(dept_id=self.dept_id)
|
|
|
|
imputation_dept = prefs["ImputationDept"]
|
2021-12-04 21:04:09 +01:00
|
|
|
if not imputation_dept:
|
2022-05-09 16:26:23 +02:00
|
|
|
imputation_dept = prefs["DeptName"]
|
2021-12-04 21:04:09 +01:00
|
|
|
imputation_dept = imputation_dept.upper()
|
2023-02-12 13:36:47 +01:00
|
|
|
cursus_name = self.formation.get_cursus().NAME
|
2021-12-04 21:04:09 +01:00
|
|
|
modalite = self.modalite
|
|
|
|
# exception pour code Apprentissage:
|
|
|
|
modalite = (modalite or "").replace("FAP", "FA").replace("APP", "FA")
|
|
|
|
if self.semestre_id > 0:
|
|
|
|
decale = "D" if self.est_decale() else ""
|
|
|
|
semestre_id = f"S{self.semestre_id}{decale}"
|
|
|
|
else:
|
|
|
|
semestre_id = self.formation.code_specialite or ""
|
|
|
|
annee_sco = str(
|
|
|
|
scu.annee_scolaire_debut(self.date_debut.year, self.date_debut.month)
|
|
|
|
)
|
|
|
|
return scu.sanitize_string(
|
2023-02-12 13:36:47 +01:00
|
|
|
f"{imputation_dept}-{cursus_name}-{modalite}-{semestre_id}-{annee_sco}"
|
2021-12-04 21:04:09 +01:00
|
|
|
)
|
|
|
|
|
2022-02-10 22:35:55 +01:00
|
|
|
def titre_annee(self) -> str:
|
2022-11-13 14:55:18 +01:00
|
|
|
"""Le titre avec l'année
|
|
|
|
'DUT Réseaux et Télécommunications semestre 3 FAP 2020-2021'
|
|
|
|
"""
|
2022-02-10 22:35:55 +01:00
|
|
|
titre_annee = (
|
|
|
|
f"{self.titre_num()} {self.modalite or ''} {self.date_debut.year}"
|
|
|
|
)
|
|
|
|
if self.date_fin.year != self.date_debut.year:
|
|
|
|
titre_annee += "-" + str(self.date_fin.year)
|
|
|
|
return titre_annee
|
|
|
|
|
2023-02-12 23:03:12 +01:00
|
|
|
def titre_formation(self, with_sem_idx=False):
|
2022-05-09 16:26:23 +02:00
|
|
|
"""Titre avec formation, court, pour passerelle: "BUT R&T"
|
|
|
|
(méthode de formsemestre car on pourrait ajouter le semestre, ou d'autres infos, à voir)
|
|
|
|
"""
|
2023-02-12 23:03:12 +01:00
|
|
|
if with_sem_idx and self.semestre_id > 0:
|
|
|
|
return f"{self.formation.acronyme} S{self.semestre_id}"
|
2022-05-09 16:26:23 +02:00
|
|
|
return self.formation.acronyme
|
|
|
|
|
2021-12-10 00:54:57 +01:00
|
|
|
def titre_mois(self) -> str:
|
|
|
|
"""Le titre et les dates du semestre, pour affichage dans des listes
|
|
|
|
Ex: "BUT QLIO (PN 2022) semestre 1 FI (Sept 2022 - Jan 2023)"
|
|
|
|
"""
|
|
|
|
return f"""{self.titre_num()} {self.modalite or ''} ({
|
|
|
|
scu.MONTH_NAMES_ABBREV[self.date_debut.month-1]} {
|
|
|
|
self.date_debut.year} - {
|
|
|
|
scu.MONTH_NAMES_ABBREV[self.date_fin.month -1]} {
|
|
|
|
self.date_fin.year})"""
|
|
|
|
|
|
|
|
def titre_num(self) -> str:
|
2022-01-20 13:00:25 +01:00
|
|
|
"""Le titre et le semestre, ex ""DUT Informatique semestre 2"" """
|
2023-02-12 13:36:47 +01:00
|
|
|
if self.semestre_id == codes_cursus.NO_SEMESTRE_ID:
|
2021-12-10 00:54:57 +01:00
|
|
|
return self.titre
|
2023-02-12 13:36:47 +01:00
|
|
|
return f"{self.titre} {self.formation.get_cursus().SESSION_NAME} {self.semestre_id}"
|
2021-12-10 00:54:57 +01:00
|
|
|
|
2022-04-12 17:12:51 +02:00
|
|
|
def sem_modalite(self) -> str:
|
2022-04-20 22:55:40 +02:00
|
|
|
"""Le semestre et la modalité, ex "S2 FI" ou "S3 APP" """
|
2022-04-12 17:12:51 +02:00
|
|
|
if self.semestre_id > 0:
|
|
|
|
descr_sem = f"S{self.semestre_id}"
|
|
|
|
else:
|
|
|
|
descr_sem = ""
|
|
|
|
if self.modalite:
|
|
|
|
descr_sem += " " + self.modalite
|
|
|
|
return descr_sem
|
|
|
|
|
2024-03-17 13:28:49 +01:00
|
|
|
def get_abs_count(self, etudid) -> tuple[int, int, int]:
|
2021-12-11 16:46:15 +01:00
|
|
|
"""Les comptes d'absences de cet étudiant dans ce semestre:
|
2024-03-01 12:40:05 +01:00
|
|
|
tuple (nb abs non just, nb abs justifiées, nb abs total)
|
2021-12-11 16:46:15 +01:00
|
|
|
Utilise un cache.
|
|
|
|
"""
|
2023-06-30 15:34:50 +02:00
|
|
|
from app.scodoc import sco_assiduites
|
2021-12-11 16:46:15 +01:00
|
|
|
|
2023-05-30 15:11:09 +02:00
|
|
|
metrique = sco_preferences.get_preference("assi_metrique", self.id)
|
2023-06-30 15:34:50 +02:00
|
|
|
return sco_assiduites.get_assiduites_count_in_interval(
|
2023-08-19 16:17:21 +02:00
|
|
|
etudid,
|
|
|
|
self.date_debut.isoformat(),
|
|
|
|
self.date_fin.isoformat(),
|
|
|
|
translate_assiduites_metric(metrique),
|
2021-12-11 16:46:15 +01:00
|
|
|
)
|
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
def get_codes_apogee(self, category=None) -> set[str]:
|
|
|
|
"""Les codes Apogée (codés en base comme "VRT1,VRT2")
|
2024-06-24 03:37:40 +02:00
|
|
|
category:
|
|
|
|
None: tous,
|
|
|
|
"etapes": étapes associées,
|
|
|
|
"sem: code semestre"
|
|
|
|
"annee": code annuel
|
|
|
|
"passage": code passage
|
2022-07-05 16:09:26 +02:00
|
|
|
"""
|
|
|
|
codes = set()
|
|
|
|
if category is None or category == "etapes":
|
|
|
|
codes |= {e.etape_apo for e in self.etapes if e}
|
|
|
|
if (category is None or category == "sem") and self.elt_sem_apo:
|
|
|
|
codes |= {x.strip() for x in self.elt_sem_apo.split(",") if x}
|
|
|
|
if (category is None or category == "annee") and self.elt_annee_apo:
|
|
|
|
codes |= {x.strip() for x in self.elt_annee_apo.split(",") if x}
|
2024-06-24 03:37:40 +02:00
|
|
|
if (category is None or category == "passage") and self.elt_passage_apo:
|
|
|
|
codes |= {x.strip() for x in self.elt_passage_apo.split(",") if x}
|
2022-07-05 16:09:26 +02:00
|
|
|
return codes
|
|
|
|
|
2024-08-11 23:24:40 +02:00
|
|
|
def get_inscrits(
|
|
|
|
self, include_demdef=False, order=False, etats: set | None = None
|
|
|
|
) -> list[Identite]:
|
2021-12-14 23:03:59 +01:00
|
|
|
"""Liste des étudiants inscrits à ce semestre
|
2022-01-16 23:47:52 +01:00
|
|
|
Si include_demdef, tous les étudiants, avec les démissionnaires
|
|
|
|
et défaillants.
|
2024-08-11 23:24:40 +02:00
|
|
|
Si etats, seuls les étudiants dans l'un des états indiqués.
|
2022-02-13 13:58:09 +01:00
|
|
|
Si order, tri par clé sort_key
|
2021-12-14 23:03:59 +01:00
|
|
|
"""
|
2022-01-16 23:47:52 +01:00
|
|
|
if include_demdef:
|
2022-02-12 22:57:46 +01:00
|
|
|
etuds = [ins.etud for ins in self.inscriptions]
|
2024-08-11 23:24:40 +02:00
|
|
|
elif not etats:
|
2022-02-12 22:57:46 +01:00
|
|
|
etuds = [ins.etud for ins in self.inscriptions if ins.etat == scu.INSCRIT]
|
2024-08-11 23:24:40 +02:00
|
|
|
else:
|
|
|
|
etuds = [ins.etud for ins in self.inscriptions if ins.etat in etats]
|
2022-02-13 13:58:09 +01:00
|
|
|
if order:
|
2022-02-12 22:57:46 +01:00
|
|
|
etuds.sort(key=lambda e: e.sort_key)
|
|
|
|
return etuds
|
2021-12-14 23:03:59 +01:00
|
|
|
|
2024-08-11 23:24:40 +02:00
|
|
|
def inscrit_etudiant(
|
|
|
|
self,
|
|
|
|
etud: "Identite",
|
|
|
|
etat: str = scu.INSCRIT,
|
|
|
|
etape: str | None = None,
|
|
|
|
method: str | None = None,
|
|
|
|
) -> "FormSemestreInscription":
|
|
|
|
"""Inscrit l'étudiant au semestre, ou renvoie son inscription s'il l'est déjà.
|
|
|
|
Vérifie la capacité d'accueil si indiquée (non null): si le semestre est plein,
|
|
|
|
lève une exception. Génère un évènement et un log étudiant.
|
|
|
|
method: indique origine de l'inscription pour le log étudiant.
|
|
|
|
"""
|
|
|
|
# remplace ancien do_formsemestre_inscription_create()
|
|
|
|
if not self.etat: # check lock
|
|
|
|
raise ScoValueError("inscrit_etudiant: semestre verrouille")
|
|
|
|
inscr = FormSemestreInscription.query.filter_by(
|
|
|
|
formsemestre_id=self.id, etudid=etud.id
|
|
|
|
).first()
|
|
|
|
if inscr is not None:
|
|
|
|
return inscr
|
|
|
|
|
|
|
|
if self.capacite_accueil is not None:
|
2024-08-12 14:40:35 +02:00
|
|
|
# tous sauf démissionnaires:
|
|
|
|
inscriptions = self.get_inscrits(etats={scu.INSCRIT, scu.DEF})
|
2024-08-11 23:24:40 +02:00
|
|
|
if len(inscriptions) >= self.capacite_accueil:
|
|
|
|
raise ScoValueError(
|
2024-08-12 14:40:35 +02:00
|
|
|
f"Semestre {self.titre} complet : {len(self.inscriptions)} inscrits",
|
|
|
|
dest_url=url_for(
|
|
|
|
"notes.formsemestre_status",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=self.id,
|
|
|
|
),
|
2024-08-11 23:24:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
inscr = FormSemestreInscription(
|
|
|
|
formsemestre_id=self.id, etudid=etud.id, etat=etat, etape=etape
|
|
|
|
)
|
|
|
|
db.session.add(inscr)
|
|
|
|
# Évènement
|
|
|
|
event = ScolarEvent(
|
|
|
|
etudid=etud.id,
|
|
|
|
formsemestre_id=self.id,
|
|
|
|
event_type="INSCRIPTION",
|
|
|
|
)
|
|
|
|
db.session.add(event)
|
|
|
|
# Log etudiant
|
|
|
|
Scolog.logdb(
|
|
|
|
method=method,
|
|
|
|
etudid=etud.id,
|
|
|
|
msg=f"inscription en semestre {self.titre_annee()}",
|
|
|
|
commit=True,
|
|
|
|
)
|
2024-08-22 16:42:38 +02:00
|
|
|
log(
|
|
|
|
f"inscrit_etudiant: {etud.nomprenom} ({etud.id}) au semestre {self.titre_annee()}"
|
|
|
|
)
|
|
|
|
# Notification mail
|
|
|
|
self._notify_inscription(etud)
|
2024-08-11 23:24:40 +02:00
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=self.id)
|
|
|
|
return inscr
|
|
|
|
|
2024-08-22 16:42:38 +02:00
|
|
|
def desinscrit_etudiant(self, etud: Identite):
|
|
|
|
"Désinscrit l'étudiant du semestre (et notifie le cas échéant)"
|
|
|
|
inscr_sem = FormSemestreInscription.query.filter_by(
|
|
|
|
etudid=etud.id, formsemestre_id=self.id
|
|
|
|
).first()
|
|
|
|
if not inscr_sem:
|
|
|
|
raise ScoValueError(
|
|
|
|
f"{etud.nomprenom} ({etud.id}) n'est pas inscrit au semestre !"
|
|
|
|
)
|
|
|
|
db.session.delete(inscr_sem)
|
|
|
|
Scolog.logdb(
|
|
|
|
method="desinscrit_etudiant",
|
|
|
|
etudid=etud.id,
|
|
|
|
msg=f"désinscription semestre {self.titre_annee()}",
|
|
|
|
commit=True,
|
|
|
|
)
|
|
|
|
log(
|
|
|
|
f"desinscrit_etudiant: {etud.nomprenom} ({etud.id}) au semestre {self.titre_annee()}"
|
|
|
|
)
|
|
|
|
self._notify_inscription(etud, action="désinscrit")
|
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=self.id)
|
|
|
|
|
|
|
|
def _notify_inscription(self, etud: Identite, action="inscrit") -> None:
|
|
|
|
"Notifie inscription d'un étudiant: envoie un mail selon paramétrage"
|
|
|
|
destinations = (
|
|
|
|
sco_preferences.get_preference("emails_notifications_inscriptions", self.id)
|
|
|
|
or ""
|
|
|
|
)
|
|
|
|
destinations = [x.strip() for x in destinations.split(",")]
|
|
|
|
destinations = [x for x in destinations if x]
|
|
|
|
if not destinations:
|
|
|
|
return
|
|
|
|
txt = f"""{etud.nom_prenom()}
|
|
|
|
s'est {action}{etud.e}
|
|
|
|
en {self.titre_annee()}"""
|
|
|
|
subject = f"""Inscription de {etud.nom_prenom()} en {self.titre_annee()}"""
|
|
|
|
# build mail
|
|
|
|
log(f"_notify_inscription: sending notification to {destinations}")
|
|
|
|
log(f"_notify_inscription: subject: {subject}")
|
|
|
|
log(txt)
|
|
|
|
email.send_email(
|
|
|
|
"[ScoDoc] " + subject, email.get_from_addr(), destinations, txt
|
|
|
|
)
|
|
|
|
|
2023-10-13 22:25:44 +02:00
|
|
|
def get_partitions_list(
|
|
|
|
self, with_default=True, only_listed=False
|
|
|
|
) -> list[Partition]:
|
2023-09-19 21:39:36 +02:00
|
|
|
"""Liste des partitions pour ce semestre (list of dicts),
|
|
|
|
triées par numéro, avec la partition par défaut en fin de liste.
|
2024-08-26 01:47:09 +02:00
|
|
|
Si only_listed, seulement les partitions indiquées "à lister" (show_in_lists).
|
2023-09-19 21:39:36 +02:00
|
|
|
"""
|
2023-10-13 22:25:44 +02:00
|
|
|
if only_listed:
|
|
|
|
partitions = [
|
|
|
|
p
|
|
|
|
for p in self.partitions
|
|
|
|
if p.partition_name is not None and p.show_in_lists
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
partitions = [p for p in self.partitions if p.partition_name is not None]
|
2023-09-19 21:39:36 +02:00
|
|
|
if with_default:
|
2023-09-19 23:04:46 +02:00
|
|
|
partitions += [p for p in self.partitions if p.partition_name is None]
|
2023-09-19 21:39:36 +02:00
|
|
|
return partitions
|
|
|
|
|
2024-03-22 11:49:51 +01:00
|
|
|
def etudids_actifs(self) -> tuple[list[int], set[int]]:
|
|
|
|
"""Liste les etudids inscrits (incluant DEM et DEF),
|
2024-06-14 20:15:20 +02:00
|
|
|
qui sera l'index des dataframes de notes
|
2024-03-22 11:49:51 +01:00
|
|
|
et donne l'ensemble des inscrits non DEM ni DEF.
|
|
|
|
"""
|
|
|
|
return [inscr.etudid for inscr in self.inscriptions], {
|
|
|
|
ins.etudid for ins in self.inscriptions if ins.etat == scu.INSCRIT
|
|
|
|
}
|
2022-01-30 13:11:17 +01:00
|
|
|
|
2024-04-05 11:00:01 +02:00
|
|
|
@property
|
2021-12-30 23:58:38 +01:00
|
|
|
def etuds_inscriptions(self) -> dict:
|
2022-01-16 23:47:52 +01:00
|
|
|
"""Map { etudid : inscription } (incluant DEM et DEF)"""
|
2021-12-30 23:58:38 +01:00
|
|
|
return {ins.etud.id: ins for ins in self.inscriptions}
|
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
def setup_parcours_groups(self) -> None:
|
|
|
|
"""Vérifie et créee si besoin la partition et les groupes de parcours BUT."""
|
|
|
|
if not self.formation.is_apc():
|
|
|
|
return
|
|
|
|
partition = Partition.query.filter_by(
|
|
|
|
formsemestre_id=self.id, partition_name=scu.PARTITION_PARCOURS
|
|
|
|
).first()
|
|
|
|
if partition is None:
|
|
|
|
# Création de la partition de parcours
|
|
|
|
partition = Partition(
|
|
|
|
formsemestre_id=self.id,
|
|
|
|
partition_name=scu.PARTITION_PARCOURS,
|
|
|
|
numero=-1,
|
2022-08-03 21:42:53 +02:00
|
|
|
groups_editable=False,
|
2022-07-05 16:09:26 +02:00
|
|
|
)
|
|
|
|
db.session.add(partition)
|
|
|
|
db.session.flush() # pour avoir un id
|
2022-08-30 20:31:05 +02:00
|
|
|
flash("Partition Parcours créée.")
|
2022-12-17 13:43:47 +01:00
|
|
|
elif partition.groups_editable:
|
|
|
|
# Il ne faut jamais laisser éditer cette partition de parcours
|
|
|
|
partition.groups_editable = False
|
|
|
|
db.session.add(partition)
|
2022-07-05 16:09:26 +02:00
|
|
|
|
2022-12-17 13:43:47 +01:00
|
|
|
for parcour in self.get_parcours_apc():
|
2022-07-05 16:09:26 +02:00
|
|
|
if parcour.code:
|
|
|
|
group = GroupDescr.query.filter_by(
|
|
|
|
partition_id=partition.id, group_name=parcour.code
|
|
|
|
).first()
|
|
|
|
if not group:
|
|
|
|
partition.groups.append(GroupDescr(group_name=parcour.code))
|
2022-11-01 19:25:15 +01:00
|
|
|
db.session.flush()
|
|
|
|
# S'il reste des groupes de parcours qui ne sont plus dans le semestre
|
2022-12-17 13:43:47 +01:00
|
|
|
# - s'ils n'ont pas d'inscrits, supprime-les.
|
|
|
|
# - s'ils ont des inscrits: avertissement
|
2022-11-01 19:25:15 +01:00
|
|
|
for group in GroupDescr.query.filter_by(partition_id=partition.id):
|
2022-12-17 14:05:13 +01:00
|
|
|
if group.group_name not in (p.code for p in self.get_parcours_apc()):
|
2022-12-17 13:43:47 +01:00
|
|
|
if (
|
|
|
|
len(
|
|
|
|
[
|
|
|
|
inscr
|
|
|
|
for inscr in self.inscriptions
|
|
|
|
if (inscr.parcour is not None)
|
|
|
|
and inscr.parcour.code == group.group_name
|
|
|
|
]
|
|
|
|
)
|
|
|
|
== 0
|
|
|
|
):
|
|
|
|
flash(f"Suppression du groupe de parcours vide {group.group_name}")
|
|
|
|
db.session.delete(group)
|
|
|
|
else:
|
|
|
|
flash(
|
|
|
|
f"""Attention: groupe de parcours {group.group_name} non vide:
|
|
|
|
réaffectez ses étudiants dans des parcours du semestre"""
|
|
|
|
)
|
2022-11-01 19:25:15 +01:00
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
db.session.commit()
|
|
|
|
|
2023-07-31 18:46:41 +02:00
|
|
|
def update_inscriptions_parcours_from_groups(self, etudid: int = None) -> None:
|
2022-07-05 16:09:26 +02:00
|
|
|
"""Met à jour les inscriptions dans les parcours du semestres en
|
|
|
|
fonction des groupes de parcours.
|
2023-07-31 18:46:41 +02:00
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
Les groupes de parcours sont ceux de la partition scu.PARTITION_PARCOURS
|
|
|
|
et leur nom est le code du parcours (eg "Cyber").
|
2023-07-31 18:46:41 +02:00
|
|
|
|
2023-08-31 13:38:17 +02:00
|
|
|
Si etudid est spécifié, n'affecte que cet étudiant,
|
2023-07-31 18:46:41 +02:00
|
|
|
sinon traite tous les inscrits du semestre.
|
2022-07-05 16:09:26 +02:00
|
|
|
"""
|
2023-06-07 17:05:33 +02:00
|
|
|
if self.formation.referentiel_competence_id is None:
|
|
|
|
return # safety net
|
2022-07-05 16:09:26 +02:00
|
|
|
partition = Partition.query.filter_by(
|
|
|
|
formsemestre_id=self.id, partition_name=scu.PARTITION_PARCOURS
|
|
|
|
).first()
|
|
|
|
if partition is None: # pas de partition de parcours
|
|
|
|
return
|
|
|
|
|
|
|
|
# Efface les inscriptions aux parcours:
|
2023-07-31 18:46:41 +02:00
|
|
|
if etudid:
|
|
|
|
db.session.execute(
|
|
|
|
text(
|
|
|
|
"""UPDATE notes_formsemestre_inscription
|
|
|
|
SET parcour_id=NULL
|
|
|
|
WHERE formsemestre_id=:formsemestre_id
|
|
|
|
AND etudid=:etudid
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
{
|
|
|
|
"formsemestre_id": self.id,
|
|
|
|
"etudid": etudid,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
db.session.execute(
|
|
|
|
text(
|
|
|
|
"""UPDATE notes_formsemestre_inscription
|
|
|
|
SET parcour_id=NULL
|
|
|
|
WHERE formsemestre_id=:formsemestre_id
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
{
|
|
|
|
"formsemestre_id": self.id,
|
|
|
|
},
|
|
|
|
)
|
2022-07-05 16:09:26 +02:00
|
|
|
# Inscrit les étudiants des groupes de parcours:
|
|
|
|
for group in partition.groups:
|
2022-07-10 12:08:22 +02:00
|
|
|
query = (
|
|
|
|
ApcParcours.query.filter_by(code=group.group_name)
|
|
|
|
.join(ApcReferentielCompetences)
|
2023-06-07 17:05:33 +02:00
|
|
|
.filter_by(
|
|
|
|
dept_id=g.scodoc_dept_id,
|
|
|
|
id=self.formation.referentiel_competence_id,
|
|
|
|
)
|
2022-07-10 12:08:22 +02:00
|
|
|
)
|
2022-07-05 16:09:26 +02:00
|
|
|
if query.count() != 1:
|
|
|
|
log(
|
|
|
|
f"""update_inscriptions_parcours_from_groups: {
|
|
|
|
query.count()} parcours with code {group.group_name}"""
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
parcour = query.first()
|
2023-07-31 18:46:41 +02:00
|
|
|
if etudid:
|
|
|
|
db.session.execute(
|
|
|
|
text(
|
|
|
|
"""UPDATE notes_formsemestre_inscription ins
|
|
|
|
SET parcour_id=:parcour_id
|
|
|
|
FROM group_membership gm
|
|
|
|
WHERE formsemestre_id=:formsemestre_id
|
|
|
|
AND ins.etudid = :etudid
|
|
|
|
AND gm.etudid = :etudid
|
|
|
|
AND gm.group_id = :group_id
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
{
|
|
|
|
"etudid": etudid,
|
|
|
|
"formsemestre_id": self.id,
|
|
|
|
"parcour_id": parcour.id,
|
|
|
|
"group_id": group.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
db.session.execute(
|
|
|
|
text(
|
|
|
|
"""UPDATE notes_formsemestre_inscription ins
|
|
|
|
SET parcour_id=:parcour_id
|
|
|
|
FROM group_membership gm
|
|
|
|
WHERE formsemestre_id=:formsemestre_id
|
|
|
|
AND gm.etudid = ins.etudid
|
|
|
|
AND gm.group_id = :group_id
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
{
|
|
|
|
"formsemestre_id": self.id,
|
|
|
|
"parcour_id": parcour.id,
|
|
|
|
"group_id": group.id,
|
|
|
|
},
|
|
|
|
)
|
2022-07-05 16:09:26 +02:00
|
|
|
db.session.commit()
|
2024-10-19 23:52:35 +02:00
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id=self.id)
|
2022-07-05 16:09:26 +02:00
|
|
|
|
2022-10-01 10:39:46 +02:00
|
|
|
def etud_validations_description_html(self, etudid: int) -> str:
|
|
|
|
"""Description textuelle des validations de jury de cet étudiant dans ce semestre"""
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.models.but_validations import ApcValidationAnnee, ApcValidationRCUE
|
2022-10-01 10:39:46 +02:00
|
|
|
|
|
|
|
vals_sem = ScolarFormSemestreValidation.query.filter_by(
|
|
|
|
etudid=etudid, formsemestre_id=self.id, ue_id=None
|
|
|
|
).all()
|
|
|
|
vals_ues = (
|
|
|
|
ScolarFormSemestreValidation.query.filter_by(
|
|
|
|
etudid=etudid, formsemestre_id=self.id
|
|
|
|
)
|
|
|
|
.join(UniteEns)
|
2024-09-08 23:52:32 +02:00
|
|
|
.order_by(UniteEns.numero, UniteEns.acronyme)
|
2022-10-01 10:39:46 +02:00
|
|
|
.all()
|
|
|
|
)
|
|
|
|
# Validations BUT:
|
|
|
|
vals_rcues = (
|
|
|
|
ApcValidationRCUE.query.filter_by(etudid=etudid, formsemestre_id=self.id)
|
|
|
|
.join(UniteEns, ApcValidationRCUE.ue1)
|
2024-09-08 23:52:32 +02:00
|
|
|
.order_by(UniteEns.numero, UniteEns.acronyme)
|
2022-10-01 10:39:46 +02:00
|
|
|
.all()
|
|
|
|
)
|
2023-06-30 09:34:29 +02:00
|
|
|
vals_annee = ( # issues de cette année scolaire seulement
|
2022-10-01 10:39:46 +02:00
|
|
|
ApcValidationAnnee.query.filter_by(
|
|
|
|
etudid=etudid,
|
|
|
|
annee_scolaire=self.annee_scolaire(),
|
2023-06-30 09:34:29 +02:00
|
|
|
referentiel_competence_id=self.formation.referentiel_competence_id,
|
|
|
|
).all()
|
2022-10-01 10:39:46 +02:00
|
|
|
)
|
|
|
|
H = []
|
|
|
|
for vals in (vals_sem, vals_ues, vals_rcues, vals_annee):
|
|
|
|
if vals:
|
|
|
|
H.append(
|
|
|
|
f"""<ul><li>{"</li><li>".join(str(x) for x in vals)}</li></ul>"""
|
|
|
|
)
|
|
|
|
return "\n".join(H)
|
|
|
|
|
2022-10-05 23:48:54 +02:00
|
|
|
def etud_set_all_missing_notes(self, etud: Identite, value=None) -> int:
|
|
|
|
"""Met toutes les notes manquantes de cet étudiant dans ce semestre
|
|
|
|
(ie dans toutes les évaluations des modules auxquels il est inscrit et n'a pas de note)
|
|
|
|
à la valeur donnée par value, qui est en général "ATT", "ABS", "EXC".
|
|
|
|
"""
|
|
|
|
from app.scodoc import sco_saisie_notes
|
|
|
|
|
|
|
|
inscriptions = (
|
|
|
|
ModuleImplInscription.query.filter_by(etudid=etud.id)
|
|
|
|
.join(ModuleImpl)
|
|
|
|
.filter_by(formsemestre_id=self.id)
|
|
|
|
)
|
|
|
|
nb_recorded = 0
|
|
|
|
for inscription in inscriptions:
|
|
|
|
for evaluation in inscription.modimpl.evaluations:
|
|
|
|
if evaluation.get_etud_note(etud) is None:
|
|
|
|
if not sco_saisie_notes.do_evaluation_set_etud_note(
|
|
|
|
evaluation, etud, value
|
|
|
|
):
|
|
|
|
raise ScoValueError(
|
|
|
|
"erreur lors de l'enregistrement de la note"
|
|
|
|
)
|
|
|
|
nb_recorded += 1
|
|
|
|
return nb_recorded
|
|
|
|
|
2023-11-19 22:06:36 +01:00
|
|
|
def change_formation(self, formation_dest: Formation):
|
|
|
|
"""Associe ce formsemestre à une autre formation.
|
|
|
|
Ce n'est possible que si la formation destination possède des modules de
|
|
|
|
même code que ceux utilisés dans la formation d'origine du formsemestre.
|
|
|
|
S'il manque un module, l'opération est annulée.
|
|
|
|
Commit (or rollback) session.
|
|
|
|
"""
|
|
|
|
ok = True
|
|
|
|
for mi in self.modimpls:
|
|
|
|
dest_modules = formation_dest.modules.filter_by(code=mi.module.code).all()
|
|
|
|
match len(dest_modules):
|
|
|
|
case 1:
|
|
|
|
mi.module = dest_modules[0]
|
|
|
|
db.session.add(mi)
|
|
|
|
case 0:
|
|
|
|
print(f"Argh ! no module found with code={mi.module.code}")
|
|
|
|
ok = False
|
|
|
|
case _:
|
|
|
|
print(f"Arg ! several modules found with code={mi.module.code}")
|
|
|
|
ok = False
|
|
|
|
|
|
|
|
if ok:
|
|
|
|
self.formation_id = formation_dest.id
|
|
|
|
db.session.commit()
|
|
|
|
else:
|
|
|
|
db.session.rollback()
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
# Association id des utilisateurs responsables (aka directeurs des etudes) du semestre
|
|
|
|
notes_formsemestre_responsables = db.Table(
|
|
|
|
"notes_formsemestre_responsables",
|
|
|
|
db.Column(
|
|
|
|
"formsemestre_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
),
|
|
|
|
db.Column("responsable_id", db.Integer, db.ForeignKey("user.id")),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
class FormSemestreEtape(models.ScoDocModel):
|
2022-04-16 15:34:40 +02:00
|
|
|
"""Étape Apogée associée au semestre"""
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
__tablename__ = "notes_formsemestre_etapes"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
2022-05-10 10:06:51 +02:00
|
|
|
# etape_apo aurait du etre not null, mais oublié
|
2021-12-10 00:54:57 +01:00
|
|
|
etape_apo = db.Column(db.String(APO_CODE_STR_LEN), index=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-10-19 23:52:35 +02:00
|
|
|
@classmethod
|
|
|
|
def create_from_apovdi(
|
|
|
|
cls, formsemestre_id: int, apovdi: ApoEtapeVDI
|
|
|
|
) -> "FormSemestreEtape":
|
|
|
|
"Crée une instance à partir d'un objet ApoEtapeVDI. Ajoute à la session."
|
|
|
|
etape = cls(formsemestre_id=formsemestre_id, etape_apo=str(apovdi))
|
|
|
|
db.session.add(etape)
|
|
|
|
return etape
|
|
|
|
|
2022-05-10 10:06:51 +02:00
|
|
|
def __bool__(self):
|
|
|
|
"Etape False if code empty"
|
|
|
|
return self.etape_apo is not None and (len(self.etape_apo) > 0)
|
|
|
|
|
2024-06-09 15:18:03 +02:00
|
|
|
def __eq__(self, other):
|
|
|
|
if isinstance(other, ApoEtapeVDI):
|
|
|
|
return self.as_apovdi() == other
|
|
|
|
return str(self) == str(other)
|
|
|
|
|
2021-12-04 21:04:09 +01:00
|
|
|
def __repr__(self):
|
2022-05-10 10:06:51 +02:00
|
|
|
return f"<Etape {self.id} apo={self.etape_apo!r}>"
|
2021-12-04 21:04:09 +01:00
|
|
|
|
2024-06-09 15:18:03 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.etape_apo or ""
|
|
|
|
|
2024-06-18 01:21:33 +02:00
|
|
|
def as_apovdi(self) -> "ApoEtapeVDI":
|
2021-12-04 21:04:09 +01:00
|
|
|
return ApoEtapeVDI(self.etape_apo)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
class FormationModalite(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Modalités de formation, utilisées pour la présentation
|
|
|
|
(grouper les semestres, générer des codes, etc.)
|
|
|
|
"""
|
|
|
|
|
2021-08-09 11:33:04 +02:00
|
|
|
__tablename__ = "notes_form_modalites"
|
|
|
|
|
2021-08-12 13:54:56 +02:00
|
|
|
DEFAULT_MODALITE = "FI"
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-08-12 13:54:56 +02:00
|
|
|
modalite = db.Column(
|
2021-08-14 18:54:32 +02:00
|
|
|
db.String(SHORT_STR_LEN),
|
2021-08-12 13:54:56 +02:00
|
|
|
unique=True,
|
|
|
|
index=True,
|
|
|
|
default=DEFAULT_MODALITE,
|
|
|
|
server_default=DEFAULT_MODALITE,
|
|
|
|
) # code
|
2021-08-07 15:20:30 +02:00
|
|
|
titre = db.Column(db.Text()) # texte explicatif
|
|
|
|
# numero = ordre de presentation)
|
2023-04-03 17:46:31 +02:00
|
|
|
numero = db.Column(db.Integer, nullable=False, default=0)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def insert_modalites():
|
|
|
|
"""Create default modalities"""
|
|
|
|
numero = 0
|
2021-08-09 23:23:11 +02:00
|
|
|
try:
|
2023-04-03 17:40:45 +02:00
|
|
|
for code, titre in (
|
2021-11-12 22:17:46 +01:00
|
|
|
(FormationModalite.DEFAULT_MODALITE, "Formation Initiale"),
|
2021-08-09 23:23:11 +02:00
|
|
|
("FAP", "Apprentissage"),
|
|
|
|
("FC", "Formation Continue"),
|
|
|
|
("DEC", "Formation Décalées"),
|
|
|
|
("LIC", "Licence"),
|
|
|
|
("CPRO", "Contrats de Professionnalisation"),
|
|
|
|
("DIST", "À distance"),
|
|
|
|
("ETR", "À l'étranger"),
|
|
|
|
("EXT", "Extérieur"),
|
|
|
|
("OTHER", "Autres formations"),
|
|
|
|
):
|
2021-11-12 22:17:46 +01:00
|
|
|
modalite = FormationModalite.query.filter_by(modalite=code).first()
|
2021-08-09 23:23:11 +02:00
|
|
|
if modalite is None:
|
2021-11-12 22:17:46 +01:00
|
|
|
modalite = FormationModalite(
|
2021-08-09 23:23:11 +02:00
|
|
|
modalite=code, titre=titre, numero=numero
|
|
|
|
)
|
|
|
|
db.session.add(modalite)
|
|
|
|
numero += 1
|
2021-08-07 15:20:30 +02:00
|
|
|
db.session.commit()
|
2021-08-09 23:23:11 +02:00
|
|
|
except:
|
|
|
|
db.session.rollback()
|
|
|
|
raise
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
class FormSemestreUECoef(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Coef des UE capitalisees arrivant dans ce semestre"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_formsemestre_uecoef"
|
|
|
|
__table_args__ = (db.UniqueConstraint("formsemestre_id", "ue_id"),)
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
formsemestre_uecoef_id = db.synonym("id")
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
2022-02-07 16:32:04 +01:00
|
|
|
index=True,
|
2021-08-07 15:20:30 +02:00
|
|
|
)
|
|
|
|
ue_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_ue.id"),
|
2022-02-07 16:32:04 +01:00
|
|
|
index=True,
|
2021-08-07 15:20:30 +02:00
|
|
|
)
|
|
|
|
coefficient = db.Column(db.Float, nullable=False)
|
|
|
|
|
|
|
|
|
2021-12-20 20:38:21 +01:00
|
|
|
class FormSemestreUEComputationExpr(db.Model):
|
2022-02-01 17:42:43 +01:00
|
|
|
"""Formules utilisateurs pour calcul moyenne UE (désactivées en 9.2+)."""
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
__tablename__ = "notes_formsemestre_ue_computation_expr"
|
|
|
|
__table_args__ = (db.UniqueConstraint("formsemestre_id", "ue_id"),)
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
notes_formsemestre_ue_computation_expr_id = db.synonym("id")
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
|
|
|
ue_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_ue.id"),
|
|
|
|
)
|
|
|
|
# formule de calcul moyenne
|
|
|
|
computation_expr = db.Column(db.Text())
|
|
|
|
|
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
class FormSemestreCustomMenu(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Menu custom associe au semestre"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_formsemestre_custommenu"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
custommenu_id = db.synonym("id")
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
|
|
|
title = db.Column(db.Text())
|
|
|
|
url = db.Column(db.Text())
|
2021-08-10 00:23:30 +02:00
|
|
|
idx = db.Column(db.Integer, default=0, server_default="0") # rang dans le menu
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
class FormSemestreInscription(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Inscription à un semestre de formation"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_formsemestre_inscription"
|
|
|
|
__table_args__ = (db.UniqueConstraint("formsemestre_id", "etudid"),)
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
formsemestre_inscription_id = db.synonym("id")
|
|
|
|
|
2022-07-05 16:09:26 +02:00
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("identite.id", ondelete="CASCADE"), index=True
|
|
|
|
)
|
2021-08-07 15:20:30 +02:00
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
2021-12-14 23:03:59 +01:00
|
|
|
index=True,
|
2021-08-07 15:20:30 +02:00
|
|
|
)
|
2021-11-18 23:53:57 +01:00
|
|
|
etud = db.relationship(
|
|
|
|
Identite,
|
|
|
|
backref=db.backref("formsemestre_inscriptions", cascade="all, delete-orphan"),
|
|
|
|
)
|
|
|
|
formsemestre = db.relationship(
|
|
|
|
FormSemestre,
|
2021-12-17 14:24:00 +01:00
|
|
|
backref=db.backref(
|
|
|
|
"inscriptions",
|
|
|
|
cascade="all, delete-orphan",
|
2021-12-20 20:38:21 +01:00
|
|
|
order_by="FormSemestreInscription.etudid",
|
2021-12-17 14:24:00 +01:00
|
|
|
),
|
2021-11-18 23:53:57 +01:00
|
|
|
)
|
2021-08-07 15:20:30 +02:00
|
|
|
# I inscrit, D demission en cours de semestre, DEF si "defaillant"
|
2021-12-14 23:03:59 +01:00
|
|
|
etat = db.Column(db.String(CODE_STR_LEN), index=True)
|
2022-07-05 16:09:26 +02:00
|
|
|
# Etape Apogée d'inscription (ajout 2020)
|
2021-08-07 15:20:30 +02:00
|
|
|
etape = db.Column(db.String(APO_CODE_STR_LEN))
|
2022-07-05 16:09:26 +02:00
|
|
|
# Parcours (pour les BUT)
|
2023-02-09 11:56:20 +01:00
|
|
|
parcour_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("apc_parcours.id", ondelete="SET NULL"), index=True
|
|
|
|
)
|
2022-07-05 16:09:26 +02:00
|
|
|
parcour = db.relationship(ApcParcours)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2022-03-29 00:03:38 +02:00
|
|
|
def __repr__(self):
|
2022-07-05 16:09:26 +02:00
|
|
|
return f"""<{self.__class__.__name__} {self.id} etudid={self.etudid} sem={
|
2024-06-09 15:18:03 +02:00
|
|
|
self.formsemestre_id} (S{self.formsemestre.semestre_id}) etat={self.etat} {
|
|
|
|
('parcours="'+str(self.parcour.code)+'"') if self.parcour else ''
|
|
|
|
} {('etape="'+self.etape+'"') if self.etape else ''}>"""
|
2022-03-29 00:03:38 +02:00
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-08-06 22:30:30 +02:00
|
|
|
class NotesSemSet(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""semsets: ensemble de formsemestres pour exports Apogée"""
|
|
|
|
|
|
|
|
__tablename__ = "notes_semset"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
semset_id = db.synonym("id")
|
2021-08-13 00:34:58 +02:00
|
|
|
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"))
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
title = db.Column(db.Text)
|
|
|
|
annee_scolaire = db.Column(db.Integer, nullable=True, default=None)
|
2022-11-09 12:50:10 +01:00
|
|
|
sem_id = db.Column(db.Integer, nullable=False, default=0)
|
|
|
|
"période: 0 (année), 1 (Simpair), 2 (Spair)"
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2023-04-16 05:32:21 +02:00
|
|
|
def set_periode(self, periode: int):
|
|
|
|
"""Modifie la période 0 (année), 1 (Simpair), 2 (Spair)"""
|
|
|
|
if periode not in {0, 1, 2}:
|
|
|
|
raise ValueError("periode invalide")
|
|
|
|
self.sem_id = periode
|
|
|
|
log(f"semset.set_periode({self.id}, {periode})")
|
|
|
|
db.session.add(self)
|
|
|
|
db.session.commit()
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2021-09-10 21:48:04 +02:00
|
|
|
# Association: many to many
|
2021-08-07 15:20:30 +02:00
|
|
|
notes_semset_formsemestre = db.Table(
|
|
|
|
"notes_semset_formsemestre",
|
|
|
|
db.Column("formsemestre_id", db.Integer, db.ForeignKey("notes_formsemestre.id")),
|
2021-09-10 21:48:04 +02:00
|
|
|
db.Column(
|
|
|
|
"semset_id",
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_semset.id", ondelete="CASCADE"),
|
|
|
|
nullable=False,
|
|
|
|
),
|
2021-08-07 15:20:30 +02:00
|
|
|
db.UniqueConstraint("formsemestre_id", "semset_id"),
|
|
|
|
)
|