1
0
Fork 0

- Fix: invalidation cache après annulaition DEM ou DEF

- Améliore explication lorsqu'il est impossible de supprimer un semestre.
This commit is contained in:
Emmanuel Viennet 2023-06-01 19:48:52 +02:00
parent feb799cc20
commit a8ab0cb48c
3 changed files with 45 additions and 26 deletions

View File

@ -1333,11 +1333,18 @@ Ceci n'est possible que si :
cancelbutton="Annuler",
)
if tf[0] == 0:
if formsemestre_has_decisions_or_compensations(formsemestre):
has_decisions, message = formsemestre_has_decisions_or_compensations(
formsemestre
)
if has_decisions:
H.append(
"""<p><b>Ce semestre ne peut pas être supprimé !
(il y a des décisions de jury ou des compensations par d'autres semestres)</b>
</p>"""
f"""<p><b>Ce semestre ne peut pas être supprimé !</b></p>
<p>il y a des décisions de jury ou des compensations par d'autres semestres:
</p>
<ul>
<li>{message}</li>
</ul>
"""
)
else:
H.append(tf[1])
@ -1372,32 +1379,46 @@ def formsemestre_delete2(formsemestre_id, dialog_confirmed=False):
return flask.redirect(scu.ScoURL())
def formsemestre_has_decisions_or_compensations(formsemestre: FormSemestre):
def formsemestre_has_decisions_or_compensations(
formsemestre: FormSemestre,
) -> tuple[bool, str]:
"""True if decision de jury (sem. UE, RCUE, année) émanant de ce semestre
ou compensation de ce semestre par d'autres semestres
ou autorisations de passage.
"""
# Validations de semestre ou d'UEs
if ScolarFormSemestreValidation.query.filter_by(
nb_validations = ScolarFormSemestreValidation.query.filter_by(
formsemestre_id=formsemestre.id
).count():
return True
if ScolarFormSemestreValidation.query.filter_by(
).count()
if nb_validations:
return True, f"{nb_validations} validations de semestre ou d'UE"
nb_validations = ScolarFormSemestreValidation.query.filter_by(
compense_formsemestre_id=formsemestre.id
).count():
return True
).count()
if nb_validations:
return True, f"{nb_validations} compensations utilisées dans d'autres semestres"
# Autorisations d'inscription:
if ScolarAutorisationInscription.query.filter_by(
nb_validations = ScolarAutorisationInscription.query.filter_by(
origin_formsemestre_id=formsemestre.id
).count():
return True
).count()
if nb_validations:
return (
True,
f"{nb_validations} autorisations d'inscriptions émanant de ce semestre",
)
# Validations d'années BUT
if ApcValidationAnnee.query.filter_by(formsemestre_id=formsemestre.id).count():
return True
nb_validations = ApcValidationAnnee.query.filter_by(
formsemestre_id=formsemestre.id
).count()
if nb_validations:
return True, f"{nb_validations} validations d'année BUT utilisant ce semestre"
# Validations de RCUEs
if ApcValidationRCUE.query.filter_by(formsemestre_id=formsemestre.id).count():
return True
return False
nb_validations = ApcValidationRCUE.query.filter_by(
formsemestre_id=formsemestre.id
).count()
if nb_validations:
return True, f"{nb_validations} validations de RCUE utilisant ce semestre"
return False, ""
def do_formsemestre_delete(formsemestre_id):

View File

@ -175,9 +175,7 @@ def do_formsemestre_demission(
)
db.session.add(event)
db.session.commit()
sco_cache.invalidate_formsemestre(
formsemestre_id=formsemestre_id
) # > démission ou défaillance
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
if etat_new == scu.DEMISSION:
flash("Démission enregistrée")
elif etat_new == scu.DEF:

View File

@ -1306,6 +1306,8 @@ def _do_cancel_dem_or_def(
db.session.delete(event)
db.session.commit()
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
flash(f"{operation_name} annulée.")
return flask.redirect(
url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid)
@ -1755,9 +1757,7 @@ def _etudident_create_or_edit_form(edit):
# Inval semesters with this student:
to_inval = [s["formsemestre_id"] for s in etud["sems"]]
for formsemestre_id in to_inval:
sco_cache.invalidate_formsemestre(
formsemestre_id=formsemestre_id
) # > etudident_create_or_edit
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
#
return flask.redirect(
url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid)
@ -1833,7 +1833,7 @@ def etudident_delete(etudid, dialog_confirmed=False):
# Inval semestres où il était inscrit:
to_inval = [s["formsemestre_id"] for s in etud["sems"]]
for formsemestre_id in to_inval:
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id) # >
sco_cache.invalidate_formsemestre(formsemestre_id=formsemestre_id)
flash("Étudiant supprimé !")
return flask.redirect(scu.ScoURL())