forked from ScoDoc/ScoDoc
Fix: création modules (parcours)
This commit is contained in:
parent
c492cf550a
commit
61d35ddac0
@ -6,7 +6,12 @@ from flask import current_app, g
|
|||||||
from app import db
|
from app import db
|
||||||
from app import models
|
from app import models
|
||||||
from app.models import APO_CODE_STR_LEN
|
from app.models import APO_CODE_STR_LEN
|
||||||
from app.models.but_refcomp import ApcParcours, app_critiques_modules, parcours_modules
|
from app.models.but_refcomp import (
|
||||||
|
ApcParcours,
|
||||||
|
ApcReferentielCompetences,
|
||||||
|
app_critiques_modules,
|
||||||
|
parcours_modules,
|
||||||
|
)
|
||||||
from app.scodoc import sco_utils as scu
|
from app.scodoc import sco_utils as scu
|
||||||
from app.scodoc.codes_cursus import UE_SPORT
|
from app.scodoc.codes_cursus import UE_SPORT
|
||||||
from app.scodoc.sco_exceptions import ScoValueError
|
from app.scodoc.sco_exceptions import ScoValueError
|
||||||
@ -100,6 +105,33 @@ class Module(models.ScoDocModel):
|
|||||||
|
|
||||||
return args_dict
|
return args_dict
|
||||||
|
|
||||||
|
@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 'id' to excluded."""
|
||||||
|
# on ne peut pas affecter directement parcours
|
||||||
|
return super().filter_model_attributes(data, (excluded or set()) | {"parcours"})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_from_dict(cls, data: dict) -> "Module":
|
||||||
|
"""Create from given dict, add parcours"""
|
||||||
|
mod = super().create_from_dict(data)
|
||||||
|
for p in data["parcours"]:
|
||||||
|
if isinstance(p, ApcParcours):
|
||||||
|
parcour: ApcParcours = p
|
||||||
|
else:
|
||||||
|
pid = int(p)
|
||||||
|
query = ApcParcours.query.filter_by(id=pid)
|
||||||
|
if g.scodoc_dept:
|
||||||
|
query = query.join(ApcReferentielCompetences).filter_by(
|
||||||
|
dept_id=g.scodoc_dept_id
|
||||||
|
)
|
||||||
|
parcour: ApcParcours = query.first()
|
||||||
|
if parcour is None:
|
||||||
|
raise ScoValueError("Parcours invalide")
|
||||||
|
mod.parcours.append(parcour)
|
||||||
|
return mod
|
||||||
|
|
||||||
def clone(self):
|
def clone(self):
|
||||||
"""Create a new copy of this module."""
|
"""Create a new copy of this module."""
|
||||||
mod = Module(
|
mod = Module(
|
||||||
|
@ -682,8 +682,11 @@ def module_edit(
|
|||||||
"input_type": "checkbox",
|
"input_type": "checkbox",
|
||||||
"vertical": True,
|
"vertical": True,
|
||||||
"dom_id": "tf_module_parcours",
|
"dom_id": "tf_module_parcours",
|
||||||
"labels": [parcour.libelle for parcour in ref_comp.parcours]
|
"labels": [
|
||||||
+ ["Tous (tronc commun)"],
|
f" {parcour.libelle} (<b>{parcour.code}</b>)"
|
||||||
|
for parcour in ref_comp.parcours
|
||||||
|
]
|
||||||
|
+ [" Tous (tronc commun)"],
|
||||||
"allowed_values": [
|
"allowed_values": [
|
||||||
str(parcour.id) for parcour in ref_comp.parcours
|
str(parcour.id) for parcour in ref_comp.parcours
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user