WIP: Editions formations

This commit is contained in:
Emmanuel Viennet 2021-11-18 22:46:18 +01:00
parent b2c98af293
commit b28ffdd7a8
5 changed files with 57 additions and 34 deletions

View File

@ -39,9 +39,13 @@ def df_load_ue_coefs(formation_id: int, semestre_idx: int) -> pd.DataFrame:
rows = UEs, columns = modules, value = coef.
On considère toutes les UE et modules du semestre.
Unspecified coefs (not defined in db) are set to zero.
Si semestre_idx None, prend toutes les UE de la formation.
"""
ues = models.UniteEns.query.filter_by(formation_id=formation_id)
modules = models.Module.query.filter_by(formation_id=formation_id)
if semestre_idx is not None:
ues = ues.filter_by(semestre_idx=semestre_idx)
modules = modules.filter_by(semestre_id=semestre_idx)
ue_ids = [ue.id for ue in ues]
module_ids = [module.id for module in modules]
df = pd.DataFrame(columns=module_ids, index=ue_ids, dtype=float)
@ -52,4 +56,4 @@ def df_load_ue_coefs(formation_id: int, semestre_idx: int) -> pd.DataFrame:
):
df[mod_coef.module_id][mod_coef.ue_id] = mod_coef.coef
df.fillna(value=0, inplace=True)
return df
return df, ues, modules

View File

@ -1,12 +1,15 @@
/* table_editor, par Sébastien L.
*/
form.semestre_selector {
margin-top: 2ex;
}
/***************************/
/* Le tableau */
/***************************/
.tableau{
display: grid;
grid-auto-rows: minmax(24px, auto);
grid-template-columns: fit-content(50px);
gap: 2px;
margin-top: 5px;
background: #fffefa;
@ -27,7 +30,28 @@
[data-editable="true"]{
cursor: pointer;
}
/*****************/
/* Styles ScoDoc */
/*****************/
div.title_ue {
background-color: #b7d2fa;
}
.tableau>div.title_mod {
}
div.title_RESSOURCE {
background-color: #f8c844;
}
div.title_SAE {
background-color: #c6ffab;
}
div.title_STANDARD, .champs_STANDARD {
background-color: #fefefe;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='32' viewBox='0 0 16 32'%3E%3Cg fill='%239C92AC' fill-opacity='0.21'%3E%3Cpath fill-rule='evenodd' d='M0 24h4v2H0v-2zm0 4h6v2H0v-2zm0-8h2v2H0v-2zM0 0h4v2H0V0zm0 4h2v2H0V4zm16 20h-6v2h6v-2zm0 4H8v2h8v-2zm0-8h-4v2h4v-2zm0-20h-6v2h6V0zm0 4h-4v2h4V4zm-2 12h2v2h-2v-2zm0-8h2v2h-2V8zM2 8h10v2H2V8zm0 8h10v2H2v-2zm-2-4h14v2H0v-2zm4-8h6v2H4V4zm0 16h6v2H4v-2zM6 0h2v2H6V0zm0 24h2v2H6v-2z'/%3E%3C/g%3E%3C/svg%3E");
}
div.title_MALUS {
background-color: #ff4700;
}
/***************************/
/* Statut des cellules */
/***************************/

View File

@ -1,8 +1,14 @@
<form>Semestre:
<h2>Édition des coefficients des modules vers les UEs</h2>
<div class="help">
Double-cliquer pour changer une valeur.
Les valeurs sont automatiquement enregistrées au fur et à mesure.
</div>
<form class="semestre_selector">Semestre:
<select onchange="this.form.submit()"" name="semestre_idx" id="semestre_idx">
{% for i in semestre_ids %}
<option value="{{i}}" {%if semestre_idx==i%}selected{%endif%}>{{i}}</option>
{% endfor %}
<option value="" {%if semestre_idx is none%}selected{%endif%}>tous</option>
</select>
<input type="hidden" name="formation_id" value="{{formation.id}}"></input>
<span><a class="stdlink" href="{{
@ -13,24 +19,12 @@
<div class="tableau"></div>
<div class="help">
Édition des coefficients des modules veers les UE du semestre courant.
Double-cliquer pour changer une valeur.
Les valeurs sont automatiquement enregistrées au fur et à mesure.
</div>
<script>
$(function () {
let semestre_idx = $("#semestre_idx")[0].value;
if (semestre_idx >= 0) {
let base_url = "{{data_source}}";
let data_url = base_url.replace(/\/[\-0-9]*$/, "/" + semestre_idx);
console.log("data_url=", data_url);
$.getJSON(data_url, function (data) {
console.log("build_table")
build_table(data);
});
}
let data_url = "{{data_source}}";
$.getJSON(data_url, function (data) {
build_table(data);
});
});
function save(obj) {
var value = obj.innerText.trim();

View File

@ -67,20 +67,16 @@ from app.scodoc import html_sco_header
from app.scodoc.sco_permissions import Permission
@bp.route("/table_modules_ue_coefs/<int:formation_id>")
@bp.route("/table_modules_ue_coefs/<int:formation_id>/<semestre_idx>")
@scodoc
@permission_required(Permission.ScoView)
def table_modules_ue_coefs(formation_id, semestre_idx):
def table_modules_ue_coefs(formation_id, semestre_idx=None):
"""Description JSON de la table des coefs modules/UE dans une formation"""
_ = models.Formation.query.get_or_404(formation_id) # check
df = moy_ue.df_load_ue_coefs(formation_id, semestre_idx)
ues = models.UniteEns.query.filter_by(
formation_id=formation_id, semestre_idx=semestre_idx
)
modules = models.Module.query.filter_by(
formation_id=formation_id, semestre_id=semestre_idx
)
if semestre_idx == "":
semestre_idx = None
df, ues, modules = moy_ue.df_load_ue_coefs(formation_id, semestre_idx)
# Titre des modules, en ligne
col_titres_mods = [
{
@ -88,7 +84,7 @@ def table_modules_ue_coefs(formation_id, semestre_idx):
"y": row,
# "nbX": 1,
# "nbY": 1,
"style": "title_mod " + scu.ModuleType(mod.module_type).name,
"style": "title_mod title_" + scu.ModuleType(mod.module_type).name,
"data": mod.code,
"title": mod.titre,
}
@ -107,12 +103,13 @@ def table_modules_ue_coefs(formation_id, semestre_idx):
# Les champs de saisie
cells = []
for (row, mod) in enumerate(modules, start=2):
style = "champs champs_" + scu.ModuleType(mod.module_type).name
for (col, ue) in enumerate(ues, start=2):
cells.append(
{
"x": col,
"y": row,
"style": "champs",
"style": style,
"data": df[mod.id][ue.id] or "",
"editable": True,
"module_id": mod.id,
@ -154,10 +151,14 @@ def set_module_ue_coef():
@bp.route("/edit_modules_ue_coefs")
@scodoc
@permission_required(Permission.ScoChangeFormation)
def edit_modules_ue_coefs(semestre_idx=None):
def edit_modules_ue_coefs():
"""Formulaire édition grille coefs EU/modules"""
formation_id = int(request.args["formation_id"])
semestre_idx = int(request.args.get("semestre_idx", -1))
semestre_idx = request.args.get("semestre_idx", "")
if len(semestre_idx.strip()) > 0:
semestre_idx = int(semestre_idx)
else:
semestre_idx = None
formation = models.Formation.query.filter_by(
formation_id=formation_id
).first_or_404()

View File

@ -177,7 +177,7 @@ def test_modules_conformity(test_client):
evaluation.set_ue_poids_dict({ue1.id: p1, ue2.id: p2})
assert evaluation.get_ue_poids_dict() == {ue1.id: p1, ue2.id: p2}
# On n'est pas conforme car p3 est nul alors que c3 est non nul
modules_coefficients = moy_ue.df_load_ue_coefs(formation_id)
modules_coefficients, _ues, _modules = moy_ue.df_load_ue_coefs(formation_id)
assert isinstance(modules_coefficients, pd.DataFrame)
assert modules_coefficients.shape == (nb_ues, nb_mods)
evals_poids = moy_mod.df_load_evaluations_poids(moduleimpl_id)