2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Operations de base sur les formsemestres
|
|
|
|
"""
|
2022-11-09 12:50:10 +01:00
|
|
|
import datetime
|
2022-01-10 12:00:02 +01:00
|
|
|
import time
|
2022-11-13 14:55:18 +01:00
|
|
|
from operator import itemgetter
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-11-13 14:55:18 +01:00
|
|
|
from flask import g, request, url_for
|
2021-08-20 01:22:44 +02:00
|
|
|
|
2021-08-13 09:31:49 +02:00
|
|
|
import app
|
2022-11-13 14:55:18 +01:00
|
|
|
import app.scodoc.notesdb as ndb
|
|
|
|
import app.scodoc.sco_utils as scu
|
2022-01-10 12:00:02 +01:00
|
|
|
from app import log
|
2021-08-13 09:31:49 +02:00
|
|
|
from app.models import Departement
|
2023-02-18 00:13:00 +01:00
|
|
|
from app.models import Formation, FormSemestre
|
2024-10-19 23:52:35 +02:00
|
|
|
from app.scodoc import codes_cursus, sco_preferences
|
2021-06-21 10:17:16 +02:00
|
|
|
from app.scodoc.gen_tables import GenTable
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc.codes_cursus import NO_SEMESTRE_ID
|
2022-11-13 14:55:18 +01:00
|
|
|
from app.scodoc.sco_exceptions import ScoInvalidIdType, ScoValueError
|
2021-07-10 13:55:35 +02:00
|
|
|
from app.scodoc.sco_vdi import ApoEtapeVDI
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-02-03 22:00:41 +01:00
|
|
|
_formsemestreEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"notes_formsemestre",
|
|
|
|
"formsemestre_id",
|
|
|
|
(
|
|
|
|
"formsemestre_id",
|
|
|
|
"semestre_id",
|
|
|
|
"formation_id",
|
|
|
|
"titre",
|
2024-08-11 23:24:40 +02:00
|
|
|
"capacite_accueil",
|
2020-09-26 16:19:37 +02:00
|
|
|
"date_debut",
|
|
|
|
"date_fin",
|
|
|
|
"gestion_compensation",
|
|
|
|
"gestion_semestrielle",
|
|
|
|
"etat",
|
|
|
|
"bul_hide_xml",
|
2021-09-16 22:24:08 +02:00
|
|
|
"block_moyennes",
|
2022-11-01 17:39:18 +01:00
|
|
|
"block_moyenne_generale",
|
2020-09-26 16:19:37 +02:00
|
|
|
"bul_bgcolor",
|
|
|
|
"modalite",
|
|
|
|
"resp_can_edit",
|
|
|
|
"resp_can_change_ens",
|
|
|
|
"ens_can_edit_eval",
|
|
|
|
"elt_sem_apo",
|
|
|
|
"elt_annee_apo",
|
2024-06-24 03:37:40 +02:00
|
|
|
"elt_passage_apo",
|
2023-11-08 23:19:58 +01:00
|
|
|
"edt_id",
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
2021-08-13 00:34:58 +02:00
|
|
|
filter_dept=True,
|
2020-09-26 16:19:37 +02:00
|
|
|
sortkey="date_debut",
|
|
|
|
output_formators={
|
2021-02-03 22:00:41 +01:00
|
|
|
"date_debut": ndb.DateISOtoDMY,
|
|
|
|
"date_fin": ndb.DateISOtoDMY,
|
2020-09-26 16:19:37 +02:00
|
|
|
},
|
|
|
|
input_formators={
|
2021-02-03 22:00:41 +01:00
|
|
|
"date_debut": ndb.DateDMYtoISO,
|
|
|
|
"date_fin": ndb.DateDMYtoISO,
|
2021-08-10 09:10:36 +02:00
|
|
|
"etat": bool,
|
2021-08-10 12:57:38 +02:00
|
|
|
"bul_hide_xml": bool,
|
2021-09-16 22:24:08 +02:00
|
|
|
"block_moyennes": bool,
|
2022-11-01 17:39:18 +01:00
|
|
|
"block_moyenne_generale": bool,
|
2021-08-11 00:36:07 +02:00
|
|
|
"gestion_compensation": bool,
|
|
|
|
"gestion_semestrielle": bool,
|
|
|
|
"resp_can_edit": bool,
|
|
|
|
"resp_can_change_ens": bool,
|
|
|
|
"ens_can_edit_eval": bool,
|
2023-01-11 13:37:02 +01:00
|
|
|
"bul_bgcolor": lambda color: color or "white",
|
|
|
|
"titre": lambda titre: titre or "sans titre",
|
2020-09-26 16:19:37 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-07-26 13:27:57 +02:00
|
|
|
def get_formsemestre(formsemestre_id: int) -> dict:
|
2020-09-26 16:19:37 +02:00
|
|
|
"list ONE formsemestre"
|
2022-04-21 16:35:27 +02:00
|
|
|
if formsemestre_id is None:
|
2022-11-13 14:55:18 +01:00
|
|
|
raise ValueError("get_formsemestre: id manquant")
|
2021-10-04 22:05:05 +02:00
|
|
|
if formsemestre_id in g.stored_get_formsemestre:
|
|
|
|
return g.stored_get_formsemestre[formsemestre_id]
|
2021-09-13 17:10:38 +02:00
|
|
|
if not isinstance(formsemestre_id, int):
|
2022-04-21 16:35:27 +02:00
|
|
|
log(f"get_formsemestre: invalid id '{formsemestre_id}'")
|
2022-07-07 23:34:14 +02:00
|
|
|
raise ScoInvalidIdType("get_formsemestre: formsemestre_id must be an integer !")
|
2021-09-30 17:50:37 +02:00
|
|
|
sems = do_formsemestre_list(args={"formsemestre_id": formsemestre_id})
|
|
|
|
if not sems:
|
2022-11-13 14:55:18 +01:00
|
|
|
log(f"get_formsemestre: invalid formsemestre_id ({formsemestre_id})")
|
2023-02-01 14:35:25 +01:00
|
|
|
raise ScoValueError(f"semestre {formsemestre_id} inconnu !")
|
|
|
|
|
2021-10-04 22:05:05 +02:00
|
|
|
g.stored_get_formsemestre[formsemestre_id] = sems[0]
|
2021-09-30 17:50:37 +02:00
|
|
|
return sems[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def do_formsemestre_list(*a, **kw):
|
2020-09-26 16:19:37 +02:00
|
|
|
"list formsemestres"
|
|
|
|
# log('do_formsemestre_list: a=%s kw=%s' % (str(a),str(kw)))
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
sems = _formsemestreEditor.list(cnx, *a, **kw)
|
|
|
|
|
|
|
|
# Ajoute les étapes Apogee et les responsables:
|
|
|
|
for sem in sems:
|
2021-08-19 10:28:35 +02:00
|
|
|
sem["etapes"] = read_formsemestre_etapes(sem["formsemestre_id"])
|
|
|
|
sem["responsables"] = read_formsemestre_responsables(sem["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Filtre sur code etape si indiqué:
|
|
|
|
if "args" in kw:
|
|
|
|
etape = kw["args"].get("etape_apo", None)
|
|
|
|
if etape:
|
|
|
|
sems = [sem for sem in sems if etape in sem["etapes"]]
|
|
|
|
|
|
|
|
for sem in sems:
|
2021-08-19 10:28:35 +02:00
|
|
|
_formsemestre_enrich(sem)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-07-09 23:19:30 +02:00
|
|
|
# tri par date, le plus récent d'abord
|
|
|
|
sems.sort(key=itemgetter("dateord", "semestre_id"), reverse=True)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
return sems
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def _formsemestre_enrich(sem):
|
2022-05-28 11:38:22 +02:00
|
|
|
"""Ajoute champs souvent utiles: titre + annee et dateord (pour tris).
|
|
|
|
XXX obsolete: préférer formsemestre.to_dict() ou, mieux, les méthodes de FormSemestre.
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
# imports ici pour eviter refs circulaires
|
2021-07-12 00:25:23 +02:00
|
|
|
from app.scodoc import sco_formsemestre_edit
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2024-10-29 19:18:36 +01:00
|
|
|
formation: Formation = Formation.get_or_404(sem["formation_id"])
|
2023-02-18 00:13:00 +01:00
|
|
|
parcours = codes_cursus.get_cursus_from_code(formation.type_parcours)
|
2020-09-26 16:19:37 +02:00
|
|
|
# 'S1', 'S2', ... ou '' pour les monosemestres
|
|
|
|
if sem["semestre_id"] != NO_SEMESTRE_ID:
|
|
|
|
sem["sem_id_txt"] = "S%s" % sem["semestre_id"]
|
|
|
|
else:
|
|
|
|
sem["sem_id_txt"] = ""
|
|
|
|
# Nom avec numero semestre:
|
|
|
|
sem["titre_num"] = sem["titre"] # eg "DUT Informatique"
|
|
|
|
if sem["semestre_id"] != NO_SEMESTRE_ID:
|
|
|
|
sem["titre_num"] += " %s %s" % (
|
|
|
|
parcours.SESSION_NAME,
|
|
|
|
sem["semestre_id"],
|
|
|
|
) # eg "DUT Informatique semestre 2"
|
|
|
|
|
2021-02-03 22:00:41 +01:00
|
|
|
sem["date_debut_iso"] = ndb.DateDMYtoISO(sem["date_debut"])
|
|
|
|
sem["date_fin_iso"] = ndb.DateDMYtoISO(sem["date_fin"])
|
2022-09-26 20:57:52 +02:00
|
|
|
sem["dateord"] = sem["date_debut_iso"] # pour les tris
|
2020-09-26 16:19:37 +02:00
|
|
|
try:
|
|
|
|
mois_debut, annee_debut = sem["date_debut"].split("/")[1:]
|
|
|
|
except:
|
|
|
|
mois_debut, annee_debut = "", ""
|
|
|
|
try:
|
|
|
|
mois_fin, annee_fin = sem["date_fin"].split("/")[1:]
|
|
|
|
except:
|
|
|
|
mois_fin, annee_fin = "", ""
|
|
|
|
sem["annee_debut"] = annee_debut
|
|
|
|
sem["annee_fin"] = annee_fin
|
|
|
|
sem["mois_debut_ord"] = int(mois_debut)
|
|
|
|
sem["mois_fin_ord"] = int(mois_fin)
|
|
|
|
|
|
|
|
sem["annee"] = annee_debut
|
|
|
|
# 2007 ou 2007-2008:
|
2021-02-04 20:02:44 +01:00
|
|
|
sem["anneescolaire"] = scu.annee_scolaire_repr(
|
|
|
|
int(annee_debut), sem["mois_debut_ord"]
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
# La période: considère comme "S1" (ou S3) les débuts en aout-sept-octobre
|
|
|
|
# devrait sans doute pouvoir etre changé...
|
|
|
|
if sem["mois_debut_ord"] >= 8 and sem["mois_debut_ord"] <= 10:
|
|
|
|
sem["periode"] = 1 # typiquement, début en septembre: S1, S3...
|
|
|
|
else:
|
|
|
|
sem["periode"] = 2 # typiquement, début en février: S2, S4...
|
|
|
|
|
|
|
|
sem["titreannee"] = "%s %s %s" % (
|
|
|
|
sem["titre_num"],
|
|
|
|
sem.get("modalite", ""),
|
|
|
|
annee_debut,
|
|
|
|
)
|
|
|
|
if annee_fin != annee_debut:
|
|
|
|
sem["titreannee"] += "-" + annee_fin
|
|
|
|
sem["annee"] += "-" + annee_fin
|
|
|
|
# et les dates sous la forme "oct 2007 - fev 2008"
|
2021-12-04 21:04:09 +01:00
|
|
|
months = scu.MONTH_NAMES_ABBREV
|
2020-09-26 16:19:37 +02:00
|
|
|
if mois_debut:
|
|
|
|
mois_debut = months[int(mois_debut) - 1]
|
|
|
|
if mois_fin:
|
|
|
|
mois_fin = months[int(mois_fin) - 1]
|
|
|
|
sem["mois_debut"] = mois_debut + " " + annee_debut
|
|
|
|
sem["mois_fin"] = mois_fin + " " + annee_fin
|
|
|
|
sem["titremois"] = "%s %s (%s - %s)" % (
|
|
|
|
sem["titre_num"],
|
|
|
|
sem.get("modalite", ""),
|
|
|
|
sem["mois_debut"],
|
|
|
|
sem["mois_fin"],
|
|
|
|
)
|
|
|
|
sem["session_id"] = sco_formsemestre_edit.get_formsemestre_session_id(
|
2023-02-18 00:13:00 +01:00
|
|
|
sem, formation.code_specialite, parcours
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2021-08-19 10:28:35 +02:00
|
|
|
sem["etapes"] = read_formsemestre_etapes(sem["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
sem["etapes_apo_str"] = formsemestre_etape_apo_str(sem)
|
2021-08-19 10:28:35 +02:00
|
|
|
sem["responsables"] = read_formsemestre_responsables(sem["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def formsemestre_etape_apo_str(sem):
|
|
|
|
"chaine décrivant le(s) codes étapes Apogée"
|
|
|
|
return etapes_apo_str(sem["etapes"])
|
|
|
|
|
|
|
|
|
|
|
|
def etapes_apo_str(etapes):
|
|
|
|
"Chaine decrivant une liste d'instance de ApoEtapeVDI"
|
|
|
|
return ", ".join([str(x) for x in etapes])
|
|
|
|
|
|
|
|
|
2024-10-19 23:52:35 +02:00
|
|
|
def read_formsemestre_responsables(formsemestre_id: int) -> list[int]: # OBSOLETE
|
2020-09-26 16:19:37 +02:00
|
|
|
"""recupere liste des responsables de ce semestre
|
2021-08-22 13:24:36 +02:00
|
|
|
:returns: liste d'id
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-08 17:38:46 +02:00
|
|
|
"""SELECT responsable_id
|
|
|
|
FROM notes_formsemestre_responsables
|
|
|
|
WHERE formsemestre_id = %(formsemestre_id)s
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
return [x["responsable_id"] for x in r]
|
|
|
|
|
|
|
|
|
2021-01-17 22:31:28 +01:00
|
|
|
# ---------------------- Coefs des UE
|
|
|
|
|
2021-02-03 22:00:41 +01:00
|
|
|
_formsemestre_uecoef_editor = ndb.EditableTable(
|
2021-01-17 22:31:28 +01:00
|
|
|
"notes_formsemestre_uecoef",
|
|
|
|
"formsemestre_uecoef_id",
|
|
|
|
("formsemestre_uecoef_id", "formsemestre_id", "ue_id", "coefficient"),
|
|
|
|
)
|
|
|
|
|
|
|
|
formsemestre_uecoef_create = _formsemestre_uecoef_editor.create
|
|
|
|
formsemestre_uecoef_edit = _formsemestre_uecoef_editor.edit
|
|
|
|
formsemestre_uecoef_list = _formsemestre_uecoef_editor.list
|
|
|
|
formsemestre_uecoef_delete = _formsemestre_uecoef_editor.delete
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def do_formsemestre_uecoef_edit_or_create(cnx, formsemestre_id, ue_id, coef):
|
2021-01-17 22:31:28 +01:00
|
|
|
"modify or create the coef"
|
|
|
|
coefs = formsemestre_uecoef_list(
|
|
|
|
cnx, args={"formsemestre_id": formsemestre_id, "ue_id": ue_id}
|
|
|
|
)
|
|
|
|
if coefs:
|
|
|
|
formsemestre_uecoef_edit(
|
|
|
|
cnx,
|
|
|
|
args={
|
|
|
|
"formsemestre_uecoef_id": coefs[0]["formsemestre_uecoef_id"],
|
|
|
|
"coefficient": coef,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
formsemestre_uecoef_create(
|
|
|
|
cnx,
|
|
|
|
args={
|
|
|
|
"formsemestre_id": formsemestre_id,
|
|
|
|
"ue_id": ue_id,
|
|
|
|
"coefficient": coef,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def do_formsemestre_uecoef_delete(cnx, formsemestre_id, ue_id):
|
2021-01-17 22:31:28 +01:00
|
|
|
"delete coef for this (ue,sem)"
|
|
|
|
coefs = formsemestre_uecoef_list(
|
|
|
|
cnx, args={"formsemestre_id": formsemestre_id, "ue_id": ue_id}
|
|
|
|
)
|
|
|
|
if coefs:
|
|
|
|
formsemestre_uecoef_delete(cnx, coefs[0]["formsemestre_uecoef_id"])
|
|
|
|
|
|
|
|
|
2022-02-09 23:22:00 +01:00
|
|
|
def read_formsemestre_etapes(formsemestre_id): # OBSOLETE
|
2020-09-26 16:19:37 +02:00
|
|
|
"""recupere liste des codes etapes associés à ce semestre
|
|
|
|
:returns: liste d'instance de ApoEtapeVDI
|
|
|
|
"""
|
2021-02-03 22:00:41 +01:00
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-08 17:38:46 +02:00
|
|
|
"""SELECT etape_apo
|
|
|
|
FROM notes_formsemestre_etapes
|
|
|
|
WHERE formsemestre_id = %(formsemestre_id)s
|
2022-04-16 15:34:40 +02:00
|
|
|
ORDER BY etape_apo
|
2021-08-08 17:38:46 +02:00
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
{"formsemestre_id": formsemestre_id},
|
|
|
|
)
|
|
|
|
return [ApoEtapeVDI(x["etape_apo"]) for x in r if x["etape_apo"]]
|
|
|
|
|
|
|
|
|
2024-02-05 09:03:53 +01:00
|
|
|
def write_formsemestre_etapes(sem): # TODO old, à ré-écrire avec models
|
2021-08-19 10:28:35 +02:00
|
|
|
return _write_formsemestre_aux(sem, "etapes", "etape_apo")
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2024-02-05 09:03:53 +01:00
|
|
|
# TODO old, à ré-écrire avec models
|
2021-08-19 10:28:35 +02:00
|
|
|
def _write_formsemestre_aux(sem, fieldname, valuename):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""fieldname: 'etapes' ou 'responsables'
|
|
|
|
valuename: 'etape_apo' ou 'responsable_id'
|
|
|
|
"""
|
2021-02-18 08:08:29 +01:00
|
|
|
if not fieldname in sem:
|
2020-09-26 16:19:37 +02:00
|
|
|
return
|
2021-02-18 08:08:29 +01:00
|
|
|
# uniquify
|
|
|
|
values = set([str(x) for x in sem[fieldname]])
|
|
|
|
|
2021-11-12 22:17:46 +01:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-02-03 22:00:41 +01:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2020-09-26 16:19:37 +02:00
|
|
|
tablename = "notes_formsemestre_" + fieldname
|
|
|
|
try:
|
|
|
|
cursor.execute(
|
|
|
|
"DELETE from " + tablename + " where formsemestre_id = %(formsemestre_id)s",
|
|
|
|
{"formsemestre_id": sem["formsemestre_id"]},
|
|
|
|
)
|
2021-02-18 08:08:29 +01:00
|
|
|
for item in values:
|
2020-09-26 16:19:37 +02:00
|
|
|
if item:
|
|
|
|
cursor.execute(
|
|
|
|
"INSERT INTO "
|
|
|
|
+ tablename
|
|
|
|
+ " (formsemestre_id, "
|
|
|
|
+ valuename
|
|
|
|
+ ") VALUES (%(formsemestre_id)s, %("
|
|
|
|
+ valuename
|
|
|
|
+ ")s)",
|
2021-02-18 08:08:29 +01:00
|
|
|
{"formsemestre_id": sem["formsemestre_id"], valuename: item},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
except:
|
|
|
|
log("Warning: exception in write_formsemestre_aux !")
|
|
|
|
cnx.rollback()
|
|
|
|
raise
|
|
|
|
cnx.commit()
|
|
|
|
|
|
|
|
|
2021-08-19 10:28:35 +02:00
|
|
|
def sem_set_responsable_name(sem):
|
2020-09-26 16:19:37 +02:00
|
|
|
"ajoute champs responsable_name"
|
2021-11-12 22:17:46 +01:00
|
|
|
from app.scodoc import sco_users
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
sem["responsable_name"] = ", ".join(
|
|
|
|
[
|
2021-07-03 23:35:32 +02:00
|
|
|
sco_users.user_info(responsable_id)["nomprenom"]
|
2020-09-26 16:19:37 +02:00
|
|
|
for responsable_id in sem["responsables"]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-06-09 15:18:03 +02:00
|
|
|
def sem_in_annee_scolaire(sem: dict, year=False): # OBSOLETE
|
2022-11-13 14:55:18 +01:00
|
|
|
"""Test si sem appartient à l'année scolaire year (int).
|
|
|
|
N'utilise que la date de début, pivot au 1er août.
|
|
|
|
Si année non specifiée, année scolaire courante
|
|
|
|
"""
|
2024-06-09 15:18:03 +02:00
|
|
|
return FormSemestre.est_in_semestre_scolaire(
|
|
|
|
datetime.date.fromisoformat(sem["date_debut_iso"]), year, periode=0
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def sem_in_semestre_scolaire(sem, year=False, periode=None): # OBSOLETE
|
|
|
|
return FormSemestre.est_in_semestre_scolaire(
|
|
|
|
datetime.date.fromisoformat(sem["date_debut_iso"]), year, periode=periode
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2024-06-09 15:18:03 +02:00
|
|
|
def sem_est_courant(sem: dict): # -> FormSemestre.est_courant
|
2021-01-02 22:07:38 +01:00
|
|
|
"""Vrai si la date actuelle (now) est dans le semestre (les dates de début et fin sont incluses)"""
|
|
|
|
now = time.strftime("%Y-%m-%d")
|
2021-02-03 22:00:41 +01:00
|
|
|
debut = ndb.DateDMYtoISO(sem["date_debut"])
|
|
|
|
fin = ndb.DateDMYtoISO(sem["date_fin"])
|
2022-11-13 14:55:18 +01:00
|
|
|
return debut <= now <= fin
|
2021-01-02 22:07:38 +01:00
|
|
|
|
|
|
|
|
2021-08-13 09:31:49 +02:00
|
|
|
def scodoc_get_all_unlocked_sems():
|
|
|
|
"""Liste de tous les semestres non verrouillés de _tous_ les départements
|
|
|
|
(utilisé pour rapports d'activités)
|
|
|
|
"""
|
|
|
|
cur_dept = g.scodoc_dept
|
|
|
|
depts = Departement.query.filter_by(visible=True).all()
|
2020-09-26 16:19:37 +02:00
|
|
|
semdepts = []
|
2021-08-13 09:31:49 +02:00
|
|
|
try:
|
|
|
|
for dept in depts:
|
|
|
|
app.set_sco_dept(dept.acronym)
|
2021-08-19 10:28:35 +02:00
|
|
|
semdepts += [(sem, dept) for sem in do_formsemestre_list() if sem["etat"]]
|
2021-08-13 09:31:49 +02:00
|
|
|
finally:
|
|
|
|
app.set_sco_dept(cur_dept)
|
2020-09-26 16:19:37 +02:00
|
|
|
return semdepts
|
|
|
|
|
|
|
|
|
|
|
|
def table_formsemestres(
|
2022-11-13 14:55:18 +01:00
|
|
|
sems: list[dict],
|
2020-09-26 16:19:37 +02:00
|
|
|
columns_ids=(),
|
|
|
|
sup_columns_ids=(),
|
|
|
|
html_title="<h2>Semestres</h2>",
|
|
|
|
html_next_section="",
|
|
|
|
):
|
2020-12-12 17:22:54 +01:00
|
|
|
"""Une table presentant des semestres"""
|
2020-09-26 16:19:37 +02:00
|
|
|
for sem in sems:
|
2024-03-21 12:06:34 +01:00
|
|
|
sem_set_responsable_name(sem) # TODO utiliser formsemestre.responsables_str()
|
2022-11-13 14:55:18 +01:00
|
|
|
sem["_titre_num_target"] = url_for(
|
|
|
|
"notes.formsemestre_status",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=sem["formsemestre_id"],
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if not columns_ids:
|
|
|
|
columns_ids = (
|
|
|
|
"etat",
|
|
|
|
"modalite",
|
|
|
|
"mois_debut",
|
|
|
|
"mois_fin",
|
|
|
|
"titre_num",
|
|
|
|
"responsable_name",
|
|
|
|
"etapes_apo_str",
|
|
|
|
)
|
|
|
|
columns_ids += sup_columns_ids
|
|
|
|
|
|
|
|
titles = {
|
|
|
|
"modalite": "",
|
|
|
|
"mois_debut": "Début",
|
|
|
|
"mois_fin": "Fin",
|
|
|
|
"titre_num": "Semestre",
|
|
|
|
"responsable_name": "Resp.",
|
|
|
|
"etapes_apo_str": "Apo.",
|
|
|
|
}
|
|
|
|
if sems:
|
2021-07-28 17:03:54 +02:00
|
|
|
preferences = sco_preferences.SemPreferences(sems[0]["formsemestre_id"])
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2021-07-28 17:03:54 +02:00
|
|
|
preferences = sco_preferences.SemPreferences()
|
2020-09-26 16:19:37 +02:00
|
|
|
tab = GenTable(
|
|
|
|
columns_ids=columns_ids,
|
|
|
|
html_class="table_leftalign",
|
2024-05-22 00:06:30 +02:00
|
|
|
html_empty_element="<p><em>aucun résultat</em></p>",
|
|
|
|
html_next_section=html_next_section,
|
2020-09-26 16:19:37 +02:00
|
|
|
html_sortable=True,
|
|
|
|
html_title=html_title,
|
|
|
|
page_title="Semestres",
|
|
|
|
preferences=preferences,
|
2024-05-22 00:06:30 +02:00
|
|
|
rows=sems,
|
|
|
|
table_id="table_formsemestres",
|
|
|
|
titles=titles,
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
return tab
|
|
|
|
|
|
|
|
|
2022-11-13 14:55:18 +01:00
|
|
|
def list_formsemestre_by_etape(etape_apo=False, annee_scolaire=False) -> list[dict]:
|
|
|
|
"""Liste des semestres de cette etape,
|
|
|
|
pour l'annee scolaire indiquée (sinon, pour toutes).
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
ds = {} # formsemestre_id : sem
|
|
|
|
if etape_apo:
|
2021-08-19 10:28:35 +02:00
|
|
|
sems = do_formsemestre_list(args={"etape_apo": etape_apo})
|
2020-09-26 16:19:37 +02:00
|
|
|
for sem in sems:
|
|
|
|
if annee_scolaire: # restriction annee scolaire
|
2021-08-19 10:28:35 +02:00
|
|
|
if sem_in_annee_scolaire(sem, year=int(annee_scolaire)):
|
2020-09-26 16:19:37 +02:00
|
|
|
ds[sem["formsemestre_id"]] = sem
|
2021-07-09 17:47:06 +02:00
|
|
|
sems = list(ds.values())
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2021-08-19 10:28:35 +02:00
|
|
|
sems = do_formsemestre_list()
|
2020-09-26 16:19:37 +02:00
|
|
|
if annee_scolaire:
|
|
|
|
sems = [
|
|
|
|
sem
|
|
|
|
for sem in sems
|
2021-08-19 10:28:35 +02:00
|
|
|
if sem_in_annee_scolaire(sem, year=int(annee_scolaire))
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
sems.sort(key=lambda s: (s["modalite"], s["dateord"]))
|
|
|
|
return sems
|
|
|
|
|
|
|
|
|
2023-09-21 10:20:19 +02:00
|
|
|
def view_formsemestre_by_etape(etape_apo=None, fmt="html"):
|
2020-12-12 17:22:54 +01:00
|
|
|
"""Affiche table des semestres correspondants à l'étape"""
|
2020-09-26 16:19:37 +02:00
|
|
|
if etape_apo:
|
2022-11-13 14:55:18 +01:00
|
|
|
html_title = f"""<h2>Semestres courants de l'étape <tt>{etape_apo}</tt></h2>"""
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
|
|
|
html_title = """<h2>Semestres courants</h2>"""
|
|
|
|
tab = table_formsemestres(
|
|
|
|
list_formsemestre_by_etape(
|
2022-11-13 14:55:18 +01:00
|
|
|
etape_apo=etape_apo, annee_scolaire=scu.annee_scolaire()
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
|
|
|
html_title=html_title,
|
|
|
|
html_next_section="""<form action="view_formsemestre_by_etape">
|
2023-11-08 23:19:58 +01:00
|
|
|
Etape: <input name="etape_apo" type="text" size="8"></input>
|
2020-09-26 16:19:37 +02:00
|
|
|
</form>""",
|
|
|
|
)
|
2021-09-18 10:10:02 +02:00
|
|
|
tab.base_url = "%s?etape_apo=%s" % (request.base_url, etape_apo or "")
|
2023-09-21 10:20:19 +02:00
|
|
|
return tab.make_page(fmt=fmt)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def sem_has_etape(sem, code_etape):
|
|
|
|
return code_etape in sem["etapes"]
|