forked from ScoDoc/ScoDoc
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
from flask import g, url_for
|
|
from flask_wtf import FlaskForm
|
|
from wtforms.fields import SelectField, SelectMultipleField
|
|
|
|
from app.models import ApcParcours, ApcReferentielCompetences, UniteEns
|
|
|
|
|
|
class UEParcoursNiveauForm(FlaskForm):
|
|
"Formulaire association parcours et niveau de compétence à une UE"
|
|
niveau_select = SelectField(
|
|
"Niveau de compétence:", render_kw={"class": "niveau_select"}
|
|
)
|
|
parcours_multiselect = SelectMultipleField(
|
|
"Parcours :",
|
|
coerce=int,
|
|
option_widget={"class": "form-check-input"},
|
|
# widget_attrs={"class": "form-check"},
|
|
render_kw={"class": "multiselect select_ue_parcours", "multiple": "multiple"},
|
|
)
|
|
|
|
def __init__(self, ue: UniteEns, parcours: list[ApcParcours], *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Initialise le menu des niveaux:
|
|
self.niveau_select.render_kw["data-ue_id"] = ue.id
|
|
self.niveau_select.choices = [
|
|
(r.id, f"{r.type_titre} {r.specialite_long} ({r.get_version()})")
|
|
for r in ApcReferentielCompetences.query.filter_by(dept_id=g.scodoc_dept_id)
|
|
]
|
|
# Initialise le menu des parcours
|
|
self.parcours_multiselect.render_kw["data-set_ue_parcours"] = url_for(
|
|
"apiweb.set_ue_parcours", ue_id=ue.id, scodoc_dept=g.scodoc_dept
|
|
)
|
|
parcours_options = [(str(p.id), f"{p.libelle} ({p.code})") for p in parcours]
|
|
self.parcours_multiselect.choices = parcours_options
|
|
|
|
# initialize checked items based on u instance
|
|
parcours_selected = [str(p.id) for p in ue.parcours]
|
|
self.parcours_multiselect.process_data(parcours_selected)
|