Fixes: cascades et invalidations de caches

This commit is contained in:
Emmanuel Viennet 2021-12-13 23:44:13 +01:00
parent 862ffb89a1
commit 5e492dc145
4 changed files with 92 additions and 5 deletions

View File

@ -78,6 +78,8 @@ def check_moduleimpl_conformity(
return True # modules vides conformes return True # modules vides conformes
if nb_ues == 0: if nb_ues == 0:
return False # situation absurde (pas d'UE) return False # situation absurde (pas d'UE)
if len(modules_coefficients) != nb_ues:
raise ValueError("check_moduleimpl_conformity: nb ue incoherent")
module_evals_poids = evals_poids.transpose().sum(axis=1).to_numpy() != 0 module_evals_poids = evals_poids.transpose().sum(axis=1).to_numpy() != 0
check = all( check = all(
(modules_coefficients[moduleimpl.module.id].to_numpy() != 0) (modules_coefficients[moduleimpl.module.id].to_numpy() != 0)

View File

@ -107,9 +107,15 @@ class EvaluationUEPoids(db.Model):
""" """
evaluation_id = db.Column( evaluation_id = db.Column(
db.Integer, db.ForeignKey("notes_evaluation.id"), primary_key=True db.Integer,
db.ForeignKey("notes_evaluation.id", ondelete="CASCADE"),
primary_key=True,
)
ue_id = db.Column(
db.Integer,
db.ForeignKey("notes_ue.id", ondelete="CASCADE"),
primary_key=True,
) )
ue_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), primary_key=True)
poids = db.Column( poids = db.Column(
db.Float, db.Float,
nullable=False, nullable=False,

View File

@ -33,7 +33,7 @@ from flask import url_for, render_template
from flask import g, request from flask import g, request
from flask_login import current_user from flask_login import current_user
from app.models import Formation, UniteEns from app.models import Formation, UniteEns, ModuleImpl, Module
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
from app.scodoc.sco_utils import ModuleType from app.scodoc.sco_utils import ModuleType
@ -106,8 +106,15 @@ def do_ue_create(args):
if ues: if ues:
raise ScoValueError('Acronyme d\'UE "%s" déjà utilisé !' % args["acronyme"]) raise ScoValueError('Acronyme d\'UE "%s" déjà utilisé !' % args["acronyme"])
# create # create
r = _ueEditor.create(cnx, args) ue_id = _ueEditor.create(cnx, args)
# Invalidate cache: vire les poids de toutes les évals de la formation
for modimpl in ModuleImpl.query.filter(
ModuleImpl.module_id == Module.id, Module.formation_id == args["formation_id"]
):
modimpl.invalidate_evaluations_poids()
formation = Formation.query.get(args["formation_id"])
formation.invalidate_module_coefs()
# news # news
F = sco_formations.formation_list(args={"formation_id": args["formation_id"]})[0] F = sco_formations.formation_list(args={"formation_id": args["formation_id"]})[0]
sco_news.add( sco_news.add(
@ -116,7 +123,7 @@ def do_ue_create(args):
text="Modification de la formation %(acronyme)s" % F, text="Modification de la formation %(acronyme)s" % F,
max_frequency=3, max_frequency=3,
) )
return r return ue_id
def do_ue_delete(ue_id, delete_validations=False, force=False): def do_ue_delete(ue_id, delete_validations=False, force=False):

View File

@ -0,0 +1,72 @@
"""cascade evaluation/poids
Revision ID: a57a6ee2e3cb
Revises: 730ac71eea23
Create Date: 2021-12-13 23:39:37.586952
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = "a57a6ee2e3cb"
down_revision = "730ac71eea23"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"evaluation_ue_poids_ue_id_fkey", "evaluation_ue_poids", type_="foreignkey"
)
op.drop_constraint(
"evaluation_ue_poids_evaluation_id_fkey",
"evaluation_ue_poids",
type_="foreignkey",
)
op.create_foreign_key(
"evaluation_ue_poids_evaluation_id_fkey",
"evaluation_ue_poids",
"notes_evaluation",
["evaluation_id"],
["id"],
ondelete="CASCADE",
)
op.create_foreign_key(
"evaluation_ue_poids_ue_id_fkey",
"evaluation_ue_poids",
"notes_ue",
["ue_id"],
["id"],
ondelete="CASCADE",
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"evaluation_ue_poids_evaluation_id_fkey",
"evaluation_ue_poids",
type_="foreignkey",
)
op.drop_constraint(
"evaluation_ue_poids_ue_id_fkey", "evaluation_ue_poids", type_="foreignkey"
)
op.create_foreign_key(
"evaluation_ue_poids_evaluation_id_fkey",
"evaluation_ue_poids",
"notes_evaluation",
["evaluation_id"],
["id"],
)
op.create_foreign_key(
"evaluation_ue_poids_ue_id_fkey",
"evaluation_ue_poids",
"notes_ue",
["ue_id"],
["id"],
)
# ### end Alembic commands ###