forked from ScoDoc/ScoDoc
Améliore initialisation poids évaluations
This commit is contained in:
parent
75c5256ba9
commit
10caea92ae
@ -100,6 +100,29 @@ class Evaluation(db.Model):
|
||||
db.session.add(copy)
|
||||
return copy
|
||||
|
||||
def set_default_poids(self) -> bool:
|
||||
"""Initialize les poids bvers les UE à leurs valeurs par défaut
|
||||
C'est à dire à 1 si le coef. module/UE est non nul, 0 sinon.
|
||||
Les poids existants ne sont pas modifiés.
|
||||
Return True if (uncommited) modification, False otherwise.
|
||||
"""
|
||||
ue_coef_dict = self.moduleimpl.module.get_ue_coef_dict()
|
||||
sem_ues = self.moduleimpl.formsemestre.query_ues(with_sport=False).all()
|
||||
modified = False
|
||||
for ue in sem_ues:
|
||||
existing_poids = EvaluationUEPoids.query.filter_by(
|
||||
ue=ue, evaluation=self
|
||||
).first()
|
||||
if existing_poids is None:
|
||||
coef_ue = ue_coef_dict.get(ue.id, 0.0) or 0.0
|
||||
if coef_ue > 0:
|
||||
poids = 1.0 # par défaut au départ
|
||||
else:
|
||||
poids = 0.0
|
||||
self.set_ue_poids(ue, poids)
|
||||
modified = True
|
||||
return modified
|
||||
|
||||
def set_ue_poids(self, ue, poids: float) -> None:
|
||||
"""Set poids évaluation vers cette UE"""
|
||||
self.update_ue_poids_dict({ue.id: poids})
|
||||
|
@ -39,6 +39,7 @@ from flask import request
|
||||
from app import db
|
||||
from app import log
|
||||
from app import models
|
||||
from app.models.evaluations import Evaluation
|
||||
from app.models.formsemestre import FormSemestre
|
||||
from app.models.moduleimpls import ModuleImpl
|
||||
import app.scodoc.sco_utils as scu
|
||||
@ -61,11 +62,17 @@ def evaluation_create_form(
|
||||
):
|
||||
"Formulaire création/édition d'une évaluation (pas de ses notes)"
|
||||
if evaluation_id is not None:
|
||||
evaluation = models.Evaluation.query.get(evaluation_id)
|
||||
evaluation: Evaluation = models.Evaluation.query.get(evaluation_id)
|
||||
if evaluation is None:
|
||||
raise ScoValueError("Cette évaluation n'existe pas ou plus !")
|
||||
moduleimpl_id = evaluation.moduleimpl_id
|
||||
#
|
||||
modimpl: ModuleImpl = (
|
||||
ModuleImpl.query.filter_by(id=moduleimpl_id)
|
||||
.join(FormSemestre)
|
||||
.filter_by(dept_id=g.scodoc_dept_id)
|
||||
.first_or_404()
|
||||
)
|
||||
modimpl_o = sco_moduleimpl.moduleimpl_withmodule_list(moduleimpl_id=moduleimpl_id)[
|
||||
0
|
||||
]
|
||||
@ -126,7 +133,7 @@ def evaluation_create_form(
|
||||
#
|
||||
H = [
|
||||
f"""<h3>{action} en
|
||||
{scu.MODULE_TYPE_NAMES[mod["module_type"]]} <a href="{
|
||||
{scu.MODULE_TYPE_NAMES[mod["module_type"]]} <a class="stdlink" href="{
|
||||
url_for("notes.moduleimpl_status",
|
||||
scodoc_dept=g.scodoc_dept, moduleimpl_id=moduleimpl_id)
|
||||
}">{mod["code"] or "module sans code"} {mod["titre"]}</a> {link}</h3>
|
||||
@ -145,25 +152,22 @@ def evaluation_create_form(
|
||||
if vals.get("tf_submitted", False) and "visibulletinlist" not in vals:
|
||||
vals["visibulletinlist"] = []
|
||||
#
|
||||
ue_coef_dict = {}
|
||||
ue_coef_dict = modimpl.module.get_ue_coef_dict()
|
||||
if is_apc: # BUT: poids vers les UE
|
||||
ue_coef_dict = ModuleImpl.query.get(moduleimpl_id).module.get_ue_coef_dict()
|
||||
for ue in sem_ues:
|
||||
if edit:
|
||||
existing_poids = models.EvaluationUEPoids.query.filter_by(
|
||||
ue=ue, evaluation=evaluation
|
||||
).first()
|
||||
else:
|
||||
existing_poids = None
|
||||
if existing_poids:
|
||||
poids = existing_poids.poids
|
||||
else:
|
||||
if edit:
|
||||
if evaluation.set_default_poids():
|
||||
db.session.commit()
|
||||
ue_poids_dict = evaluation.get_ue_poids_dict()
|
||||
for ue in sem_ues:
|
||||
initvalues[f"poids_{ue.id}"] = ue_poids_dict[ue.id]
|
||||
else:
|
||||
for ue in sem_ues:
|
||||
coef_ue = ue_coef_dict.get(ue.id, 0.0) or 0.0
|
||||
if coef_ue > 0:
|
||||
poids = 1.0 # par défaut au départ
|
||||
else:
|
||||
poids = 0.0
|
||||
initvalues[f"poids_{ue.id}"] = poids
|
||||
initvalues[f"poids_{ue.id}"] = poids
|
||||
#
|
||||
form = [
|
||||
("evaluation_id", {"default": evaluation_id, "input_type": "hidden"}),
|
||||
@ -221,7 +225,7 @@ def evaluation_create_form(
|
||||
"size": 4,
|
||||
"type": "float",
|
||||
"title": "Notes de 0 à",
|
||||
"explanation": "barème (note max actuelle: %s)" % min_note_max_str,
|
||||
"explanation": f"barème (note max actuelle: {min_note_max_str})",
|
||||
"allow_null": False,
|
||||
"max_value": scu.NOTES_MAX,
|
||||
"min_value": min_note_max,
|
||||
@ -232,7 +236,7 @@ def evaluation_create_form(
|
||||
{
|
||||
"size": 36,
|
||||
"type": "text",
|
||||
"explanation": 'type d\'évaluation, apparait sur le bulletins longs. Exemples: "contrôle court", "examen de TP", "examen final".',
|
||||
"explanation": """type d'évaluation, apparait sur le bulletins longs. Exemples: "contrôle court", "examen de TP", "examen final".""",
|
||||
},
|
||||
),
|
||||
(
|
||||
@ -320,7 +324,9 @@ def evaluation_create_form(
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
dest_url = "moduleimpl_status?moduleimpl_id=%s" % modimpl_o["moduleimpl_id"]
|
||||
dest_url = url_for(
|
||||
"notes.moduleimpl_status", scodoc_dept=g.scodoc_dept, moduleimpl_id=modimpl.id
|
||||
)
|
||||
if tf[0] == 0:
|
||||
head = html_sco_header.sco_header(page_title=page_title)
|
||||
return (
|
||||
@ -342,7 +348,7 @@ def evaluation_create_form(
|
||||
if edit:
|
||||
sco_evaluation_db.do_evaluation_edit(tf[2])
|
||||
else:
|
||||
# création d'une evaluation
|
||||
# création d'une evaluation (via fonction ScoDoc7)
|
||||
evaluation_id = sco_evaluation_db.do_evaluation_create(**tf[2])
|
||||
if is_apc:
|
||||
# Set poids
|
||||
|
@ -33,6 +33,7 @@ import time
|
||||
from flask import g, url_for
|
||||
from flask_login import current_user
|
||||
|
||||
from app import db
|
||||
from app.auth.models import User
|
||||
from app.comp import res_sem
|
||||
from app.comp.res_compat import NotesTableCompat
|
||||
@ -527,6 +528,10 @@ def _ligne_evaluation(
|
||||
H.append(f"""<tr class="{tr_class_1}"><td class="mievr_tit" colspan="8">""")
|
||||
coef = evaluation.coefficient
|
||||
if is_apc:
|
||||
if not evaluation.get_ue_poids_dict():
|
||||
# Au cas où les poids par défaut n'existent pas encore:
|
||||
if evaluation.set_default_poids():
|
||||
db.session.commit()
|
||||
coef *= sum(evaluation.get_ue_poids_dict().values())
|
||||
# Avertissement si coefs x poids nuls
|
||||
if coef < scu.NOTES_PRECISION:
|
||||
|
@ -1125,7 +1125,7 @@ def _form_dem_of_def(
|
||||
{validations_descr}
|
||||
{('<p><a class="stdlink" href="'
|
||||
+ url_for("notes.formsemestre_validation_but", scodoc_dept=g.scodoc_dept,
|
||||
formsemestre_id=formsemestre_id,etudid=etudid)
|
||||
formsemestre_id=formsemestre_id, etudid=etudid)
|
||||
+ '">modifier ces décisions</a></p>') if validations_descr else ""}
|
||||
</div>
|
||||
{html_sco_header.sco_footer()}
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
SCOVERSION = "9.3.53"
|
||||
SCOVERSION = "9.3.54"
|
||||
|
||||
SCONAME = "ScoDoc"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user