1
0
forked from ScoDoc/ScoDoc

sanitize formations after upgrades + renumber modules

This commit is contained in:
Emmanuel Viennet 2022-01-08 17:38:38 +01:00
parent 72b8e04064
commit 4c325b70de
3 changed files with 18 additions and 4 deletions

View File

@ -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()

View File

@ -449,14 +449,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):

View File

@ -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