From 24bfb8a13dc3aa9ca3ae1f25849dfa571c94b8ee Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 8 Jan 2022 19:53:17 +0100 Subject: [PATCH] 9.1.20 avec des cerises --- app/models/formations.py | 7 +++++++ app/scodoc/sco_edit_formation.py | 1 - app/scodoc/sco_edit_ue.py | 2 -- sco_version.py | 2 +- scodoc.py | 13 ++++++++++--- tools/debian/postinst | 2 +- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/models/formations.py b/app/models/formations.py index 1dfd87285..e926471c2 100644 --- a/app/models/formations.py +++ b/app/models/formations.py @@ -4,6 +4,7 @@ from app import db from app.comp import df_cache from app.models import SHORT_STR_LEN +from app.models.modules import Module from app.scodoc import notesdb as ndb from app.scodoc import sco_cache from app.scodoc import sco_codes_parcours @@ -114,6 +115,7 @@ class Formation(db.Model): return change = False for mod in self.modules: + # --- Indices de semestres: if ( mod.ue.semestre_idx is not None and mod.ue.semestre_idx > 0 @@ -122,10 +124,15 @@ class Formation(db.Model): mod.semestre_id = mod.ue.semestre_idx db.session.add(mod) change = True + # --- Types de modules if mod.module_type is None: mod.module_type = scu.ModuleType.STANDARD db.session.add(mod) change = True + # --- Numéros de modules + if Module.query.filter_by(formation_id=220, numero=None).count() > 0: + scu.objects_renumber(db, self.modules.all()) + db.session.commit() if change: self.invalidate_module_coefs() diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index a126fcebf..cb8c816af 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -306,7 +306,6 @@ def do_formation_edit(args): sco_formations._formationEditor.edit(cnx, args) formation: Formation = Formation.query.get(args["formation_id"]) formation.invalidate_cached_sems() - formation.sanitize_old_formation() def module_move(module_id, after=0, redirect=True): diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 14f8a2c96..abda43bd0 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -509,7 +509,6 @@ def ue_table(formation_id=None, semestre_idx=1, msg=""): # was ue_list formation: Formation = Formation.query.get(formation_id) if not formation: raise ScoValueError("invalid formation_id") - formation.sanitize_old_formation() parcours = formation.get_parcours() is_apc = parcours.APC_SAE locked = formation.has_locked_sems() @@ -1205,7 +1204,6 @@ def do_ue_edit(args, bypass_lock=False, dont_invalidate_cache=False): if not dont_invalidate_cache: # Invalide les semestres utilisant cette formation: formation.invalidate_cached_sems() - formation.sanitize_old_formation() # essai edition en ligne: diff --git a/sco_version.py b/sco_version.py index 272063700..aabbc6cad 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.1.19" +SCOVERSION = "9.1.20" SCONAME = "ScoDoc" diff --git a/scodoc.py b/scodoc.py index 94c8a7f09..03f656a7c 100755 --- a/scodoc.py +++ b/scodoc.py @@ -438,14 +438,21 @@ def photos_import_files(formsemestre_id: int, xlsfile: str, zipfile: str): @app.cli.command() +@click.option("--sanitize/--no-sanitize", default=False) @with_appcontext -def clear_cache(): # clear-cache +def clear_cache(sanitize): # clear-cache """Clear ScoDoc cache This cache (currently Redis) is persistent between invocation - and it may be necessary to clear it during development or tests. + and it may be necessary to clear it during upgrades, + development or tests. """ + click.echo("Flushing Redis cache...") clear_scodoc_cache() - click.echo("Redis caches flushed.") + if sanitize: + # sanitizes all formations: + click.echo("Checking formations...") + for formation in Formation.query: + formation.sanitize_old_formation() def recursive_help(cmd, parent=None): diff --git a/tools/debian/postinst b/tools/debian/postinst index 84001fc9e..33a705c2a 100755 --- a/tools/debian/postinst +++ b/tools/debian/postinst @@ -107,7 +107,7 @@ then # utilise les scripts dans migrations/version/ # pour mettre à jour notre base (en tant qu'utilisateur scodoc) export FLASK_ENV="production" - su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask db upgrade && flask clear-cache)" "$SCODOC_USER" + su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask db upgrade && flask clear-cache --sanitize)" "$SCODOC_USER" fi # ------------ LOGROTATE