From a8ab0cb48c045d2ca35b3fb78ca8462b16b2b0f6 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 1 Jun 2023 19:48:52 +0200 Subject: [PATCH] =?UTF-8?q?-=20Fix:=20invalidation=20cache=20apr=C3=A8s=20?= =?UTF-8?q?annulaition=20DEM=20ou=20DEF=20-=20Am=C3=A9liore=20explication?= =?UTF-8?q?=20lorsqu'il=20est=20impossible=20de=20supprimer=20un=20semestr?= =?UTF-8?q?e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_formsemestre_edit.py | 59 ++++++++++++++------- app/scodoc/sco_formsemestre_inscriptions.py | 4 +- app/views/scolar.py | 8 +-- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index d64bf4d9..4961e8a2 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -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( - """

Ce semestre ne peut pas être supprimé ! - (il y a des décisions de jury ou des compensations par d'autres semestres) -

""" + f"""

Ce semestre ne peut pas être supprimé !

+

il y a des décisions de jury ou des compensations par d'autres semestres: +

+ + """ ) 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): diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index f59eaa1e..82744b8f 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -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: diff --git a/app/views/scolar.py b/app/views/scolar.py index a53df3f3..19ec1c7d 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -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())