Interdit modification coefs APC si sems verrouillés

This commit is contained in:
Emmanuel Viennet 2023-02-06 10:13:01 +01:00 committed by iziram
parent c49bc44700
commit db58c57a78
3 changed files with 12 additions and 5 deletions

View File

@ -6,6 +6,7 @@ from app.models import APO_CODE_STR_LEN
from app.models.but_refcomp import ApcParcours, app_critiques_modules, parcours_modules
from app.scodoc import sco_utils as scu
from app.scodoc.sco_codes_parcours import UE_SPORT
from app.scodoc.sco_exceptions import ScoValueError
from app.scodoc.sco_utils import ModuleType
@ -175,6 +176,8 @@ class Module(db.Model):
ue_coef_dict = { ue_id : coef }
Les coefs nuls (zéro) ne sont pas stockés: la relation est supprimée.
"""
if self.formation.has_locked_sems():
raise ScoValueError("Formation verrouillée")
changed = False
for ue_id, coef in ue_coef_dict.items():
# Existant ?
@ -201,6 +204,8 @@ class Module(db.Model):
def update_ue_coef_dict(self, ue_coef_dict: dict):
"""update coefs vers UE (ajoute aux existants)"""
if self.formation.has_locked_sems():
raise ScoValueError("Formation verrouillée")
current = self.get_ue_coef_dict()
current.update(ue_coef_dict)
self.set_ue_coef_dict(current)
@ -211,6 +216,8 @@ class Module(db.Model):
def delete_ue_coef(self, ue):
"""delete coef"""
if self.formation.has_locked_sems():
raise ScoValueError("Formation verrouillée")
ue_coef = ModuleUECoef.query.get((self.id, ue.id))
if ue_coef:
db.session.delete(ue_coef)

View File

@ -813,9 +813,8 @@ du programme" (menu "Semestre") si vous avez un semestre en cours);
H.append(
f"""</li>
<li> <a class="stdlink" href="{
url_for('notes.edit_modules_ue_coefs',
scodoc_dept=g.scodoc_dept, formation_id=formation_id, semestre_idx=semestre_idx)
}">Éditer les coefficients des ressources et SAÉs</a>
url_for('notes.edit_modules_ue_coefs', scodoc_dept=g.scodoc_dept, formation_id=formation_id, semestre_idx=semestre_idx)
}">{'Visualiser' if locked else 'Éditer'} les coefficients des ressources et SAÉs</a>
</li>
</ul>
"""

View File

@ -165,7 +165,7 @@ def set_module_ue_coef():
coef = float(request.form["coef"].replace(",", "."))
except ValueError:
return scu.json_error(404, "invalid coef")
module = models.Module.query.get(module_id)
module: Module = models.Module.query.get(module_id)
if module is None:
return scu.json_error(404, f"module not found ({module_id})")
ue = models.UniteEns.query.get(ue_id)
@ -229,7 +229,8 @@ def edit_modules_ue_coefs():
"notes.set_module_ue_coef",
scodoc_dept=g.scodoc_dept,
),
read_only=not current_user.has_permission(Permission.ScoChangeFormation),
read_only=locked
or not current_user.has_permission(Permission.ScoChangeFormation),
semestre_idx=semestre_idx,
semestre_ids=range(1, formation.get_parcours().NB_SEM + 1),
parcours_id=parcours_id,