1
0
forked from ScoDoc/ScoDoc

modernise code modalite

This commit is contained in:
Emmanuel Viennet 2024-09-04 21:01:03 +02:00
parent 6cc24edc2d
commit d4e115c7fd
4 changed files with 29 additions and 66 deletions

View File

@ -25,7 +25,7 @@ from app.models import (
ScolarFormSemestreValidation, ScolarFormSemestreValidation,
) )
from app.scodoc import codes_cursus from app.scodoc import codes_cursus
from app.scodoc.sco_exceptions import ScoNoReferentielCompetences from app.scodoc.sco_exceptions import ScoNoReferentielCompetences, ScoValueError
from app.views import ScoData from app.views import ScoData
@ -38,6 +38,10 @@ def validation_rcues(etud: Identite, formsemestre: FormSemestre, edit: bool = Fa
refcomp = formation.referentiel_competence refcomp = formation.referentiel_competence
if refcomp is None: if refcomp is None:
raise ScoNoReferentielCompetences(formation=formation) raise ScoNoReferentielCompetences(formation=formation)
if etud.id not in formsemestre.etuds_inscriptions:
raise ScoValueError(
f"Etudiant {etud.nom_prenom()} non inscrit à {formsemestre.titre_mois()}"
)
parcour = formsemestre.etuds_inscriptions[etud.id].parcour parcour = formsemestre.etuds_inscriptions[etud.id].parcour
# Si non inscrit à un parcours, prend toutes les compétences # Si non inscrit à un parcours, prend toutes les compétences
competences_parcour, ects_parcours = cursus_but.parcour_formation_competences( competences_parcour, ects_parcours = cursus_but.parcour_formation_competences(

View File

@ -39,6 +39,7 @@ from app.models import (
ApcValidationAnnee, ApcValidationAnnee,
ApcValidationRCUE, ApcValidationRCUE,
Evaluation, Evaluation,
FormationModalite,
FormSemestreUECoef, FormSemestreUECoef,
Module, Module,
ModuleImpl, ModuleImpl,
@ -64,7 +65,6 @@ from app.scodoc import codes_cursus
from app.scodoc import sco_edit_module from app.scodoc import sco_edit_module
from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre
from app.scodoc import sco_groups_copy from app.scodoc import sco_groups_copy
from app.scodoc import sco_modalites
from app.scodoc import sco_moduleimpl from app.scodoc import sco_moduleimpl
from app.scodoc import sco_permissions_check from app.scodoc import sco_permissions_check
from app.scodoc import sco_portal_apogee from app.scodoc import sco_portal_apogee
@ -258,15 +258,12 @@ def do_formsemestre_createwithmodules(edit=False, formsemestre: FormSemestre = N
or m.id in module_ids_set or m.id in module_ids_set
] ]
# Pour regroupement des modules par semestres: # Pour regroupement des modules par semestres:
semestre_ids = {} semestre_ids = sorted({mod.semestre_id for mod in modules})
for mod in modules: # Liste des modalités
semestre_ids[mod.semestre_id] = 1 modalites_abbrv_titres = {
semestre_ids = list(semestre_ids.keys()) modalite.modalite: modalite.titre
semestre_ids.sort() for modalite in FormationModalite.query.order_by(FormationModalite.numero)
}
modalites = sco_modalites.do_modalite_list()
modalites_abbrv = [m["modalite"] for m in modalites]
modalites_titles = [m["titre"] for m in modalites]
# #
modform = [ modform = [
("formsemestre_id", {"input_type": "hidden"}), ("formsemestre_id", {"input_type": "hidden"}),
@ -340,8 +337,8 @@ def do_formsemestre_createwithmodules(edit=False, formsemestre: FormSemestre = N
{ {
"input_type": "menu", "input_type": "menu",
"title": "Modalité", "title": "Modalité",
"allowed_values": modalites_abbrv, "allowed_values": modalites_abbrv_titres.keys(),
"labels": modalites_titles, "labels": modalites_abbrv_titres.values(),
}, },
), ),
( (

View File

@ -34,21 +34,22 @@ Elle n'est pas utilisée pour les parcours, ni pour rien d'autre
""" """
import collections import collections
import app.scodoc.notesdb as ndb from app.models import FormSemestre, FormationModalite
from app import log
from app.models import FormSemestre
def list_formsemestres_modalites(formsemestres: list[FormSemestre]) -> list[dict]: def _list_formsemestres_modalites(
formsemestres: list[FormSemestre],
) -> list[FormationModalite]:
"""Liste ordonnée des modalités présentes dans ces formsemestres""" """Liste ordonnée des modalités présentes dans ces formsemestres"""
modalites = {} modalites = {}
for formsemestre in formsemestres: for formsemestre in formsemestres:
if formsemestre.modalite not in modalites: if formsemestre.modalite not in modalites:
m = do_modalite_list(args={"modalite": formsemestre.modalite})[0] m = FormationModalite.query.filter_by(
modalites[m["modalite"]] = m modalite=formsemestre.modalite
modalites = list(modalites.values()) ).first()
modalites.sort(key=lambda x: x["numero"]) if m is not None:
return modalites modalites[m.modalite] = m
return sorted(modalites.values(), key=lambda m: m.numero)
def group_formsemestres_by_modalite( def group_formsemestres_by_modalite(
@ -58,18 +59,18 @@ def group_formsemestres_by_modalite(
sorted in each one by semestre id and date sorted in each one by semestre id and date
""" """
sems_by_mod = collections.defaultdict(list) sems_by_mod = collections.defaultdict(list)
modalites = list_formsemestres_modalites(formsemestres) modalites = _list_formsemestres_modalites(formsemestres)
sems_by_mod = { sems_by_mod = {
modalite["modalite"]: [ modalite.modalite: [
formsemestre formsemestre
for formsemestre in formsemestres for formsemestre in formsemestres
if formsemestre.modalite == modalite["modalite"] if formsemestre.modalite == modalite.modalite
] ]
for modalite in modalites for modalite in modalites
} }
# tri dans chaque modalité par indice de semestre et date debut # tri dans chaque modalité par indice de semestre et date debut
for modalite in modalites: for modalite in modalites:
sems_by_mod[modalite["modalite"]].sort( sems_by_mod[modalite.modalite].sort(
key=lambda x: ( key=lambda x: (
x.semestre_id if x.semestre_id > 0 else -1000 * x.semestre_id, x.semestre_id if x.semestre_id > 0 else -1000 * x.semestre_id,
x.date_debut, x.date_debut,
@ -77,42 +78,3 @@ def group_formsemestres_by_modalite(
) )
return sems_by_mod, modalites return sems_by_mod, modalites
# ------ Low level interface (database) ------
_modaliteEditor = ndb.EditableTable(
"notes_form_modalites",
"form_modalite_id",
("form_modalite_id", "modalite", "titre", "numero"),
sortkey="numero",
output_formators={"numero": ndb.int_null_is_zero},
)
def do_modalite_list(*args, **kw):
"""Liste des modalites"""
cnx = ndb.GetDBConnexion()
return _modaliteEditor.list(cnx, *args, **kw)
def do_modalite_create(args):
"create a modalite"
cnx = ndb.GetDBConnexion()
r = _modaliteEditor.create(cnx, args)
return r
def do_modalite_delete(oid):
"delete a modalite"
cnx = ndb.GetDBConnexion()
log("do_modalite_delete: form_modalite_id=%s" % oid)
_modaliteEditor.delete(cnx, oid)
def do_modalite_edit(*args, **kw): # unused
"edit a modalite"
cnx = ndb.GetDBConnexion()
# check
_ = do_modalite_list({"form_modalite_id": args[0]["form_modalite_id"]})[0]
_modaliteEditor.edit(cnx, *args, **kw)

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.7.15" SCOVERSION = "9.7.16"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"