From 91cc421ef8c3733c3eb6fe727e01f1e4ae0f925e Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 16 Sep 2021 21:42:45 +0200 Subject: [PATCH] Post-migration des archives --- app/models/etudiants.py | 1 + app/models/formsemestre.py | 1 + app/scodoc/sco_archives.py | 12 ++++++------ app/scodoc/sco_archives_etud.py | 10 +++++----- app/scodoc/sco_etud.py | 1 - app/scodoc/sco_formsemestre.py | 1 - app/scodoc/sco_semset.py | 2 +- scodoc.py | 10 +++++++++- tools/__init__.py | 1 + tools/migrate_from_scodoc7.sh | 3 +++ 10 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/models/etudiants.py b/app/models/etudiants.py index 57eadbc7..a77f272e 100644 --- a/app/models/etudiants.py +++ b/app/models/etudiants.py @@ -41,6 +41,7 @@ class Identite(db.Model): code_nip = db.Column(db.Text()) code_ine = db.Column(db.Text()) # Ancien id ScoDoc7 pour les migrations de bases anciennes + # ne pas utiliser après migrate_scodoc7_dept_archive scodoc7_id = db.Column(db.Text(), nullable=True) diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 06adb3be..983448c0 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -70,6 +70,7 @@ class FormSemestre(db.Model): "NotesFormsemestreEtape", cascade="all,delete", backref="notes_formsemestre" ) # Ancien id ScoDoc7 pour les migrations de bases anciennes + # ne pas utiliser après migrate_scodoc7_dept_archive scodoc7_id = db.Column(db.Text(), nullable=True) def __init__(self, **kwargs): diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index 9381e498..f69041e9 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -34,11 +34,11 @@ Les PV de jurys et documents associés sont stockées dans un sous-repertoire de la forme /// - (formsemestre_id est ici FormSemestre.scodoc7_id ou à défaut FormSemestre.id) + (formsemestre_id est ici FormSemestre.id) Les documents liés à l'étudiant sont dans /docetuds/// -(etudid est ici soit Identite.scodoc7id, soit à défaut Identite.id) +(etudid est ici Identite.id) Les maquettes Apogée pour l'export des notes sont dans /apo_csv//-//.csv @@ -290,7 +290,7 @@ def do_formsemestre_archive( from app.scodoc.sco_recapcomplet import make_formsemestre_recapcomplet sem = sco_formsemestre.get_formsemestre(formsemestre_id) - sem_archive_id = sem["scodoc7_id"] or formsemestre_id + sem_archive_id = formsemestre_id archive_id = PVArchive.create_obj_archive(sem_archive_id, description) date = PVArchive.get_archive_date(archive_id).strftime("%d/%m/%Y à %H:%M") @@ -504,7 +504,7 @@ enregistrés et non modifiables, on peut les retrouver ultérieurement. def formsemestre_list_archives(REQUEST, formsemestre_id): """Page listing archives""" sem = sco_formsemestre.get_formsemestre(formsemestre_id) - sem_archive_id = sem["scodoc7_id"] or formsemestre_id + sem_archive_id = formsemestre_id L = [] for archive_id in PVArchive.list_obj_archives(sem_archive_id): a = { @@ -547,7 +547,7 @@ def formsemestre_list_archives(REQUEST, formsemestre_id): def formsemestre_get_archived_file(formsemestre_id, archive_name, filename): """Send file to client.""" sem = sco_formsemestre.get_formsemestre(formsemestre_id) - sem_archive_id = sem["scodoc7_id"] or formsemestre_id + sem_archive_id = formsemestre_id return PVArchive.get_archived_file(sem_archive_id, archive_name, filename) @@ -560,7 +560,7 @@ def formsemestre_delete_archive( "opération non autorisée pour %s" % str(REQUEST.AUTHENTICATED_USER) ) sem = sco_formsemestre.get_formsemestre(formsemestre_id) - sem_archive_id = sem["scodoc7_id"] or formsemestre_id + sem_archive_id = formsemestre_id archive_id = PVArchive.get_id_from_name(sem_archive_id, archive_name) dest_url = "formsemestre_list_archives?formsemestre_id=%s" % (formsemestre_id) diff --git a/app/scodoc/sco_archives_etud.py b/app/scodoc/sco_archives_etud.py index 0f199f97..157d5217 100644 --- a/app/scodoc/sco_archives_etud.py +++ b/app/scodoc/sco_archives_etud.py @@ -65,7 +65,7 @@ def etud_list_archives_html(REQUEST, etudid): if not etuds: raise ScoValueError("étudiant inexistant") etud = etuds[0] - etud_archive_id = etud["scodoc7_id"] or etudid + etud_archive_id = etudid L = [] for archive_id in EtudsArchive.list_obj_archives(etud_archive_id): a = { @@ -118,7 +118,7 @@ def add_archives_info_to_etud_list(etuds): """ for etud in etuds: l = [] - etud_archive_id = etud["scodoc7_id"] or etud["etudid"] + etud_archive_id = etud["etudid"] for archive_id in EtudsArchive.list_obj_archives(etud_archive_id): l.append( "%s (%s)" @@ -181,7 +181,7 @@ def etud_upload_file_form(REQUEST, etudid): data = tf[2]["datafile"].read() descr = tf[2]["description"] filename = tf[2]["datafile"].filename - etud_archive_id = etud["scodoc7_id"] or etud["etudid"] + etud_archive_id = etud["etudid"] _store_etud_file_to_new_archive( etud_archive_id, data, filename, description=descr ) @@ -210,7 +210,7 @@ def etud_delete_archive(REQUEST, etudid, archive_name, dialog_confirmed=False): if not etuds: raise ScoValueError("étudiant inexistant") etud = etuds[0] - etud_archive_id = etud["scodoc7_id"] or etud["etudid"] + etud_archive_id = etud["etudid"] archive_id = EtudsArchive.get_id_from_name(etud_archive_id, archive_name) if not dialog_confirmed: return scu.confirm_dialog( @@ -248,7 +248,7 @@ def etud_get_archived_file(etudid, archive_name, filename): if not etuds: raise ScoValueError("étudiant inexistant") etud = etuds[0] - etud_archive_id = etud["scodoc7_id"] or etud["etudid"] + etud_archive_id = etud["etudid"] return EtudsArchive.get_archived_file(etud_archive_id, archive_name, filename) diff --git a/app/scodoc/sco_etud.py b/app/scodoc/sco_etud.py index 46ef0aca..4142eb9a 100644 --- a/app/scodoc/sco_etud.py +++ b/app/scodoc/sco_etud.py @@ -250,7 +250,6 @@ _identiteEditor = ndb.EditableTable( "photo_filename", "code_ine", "code_nip", - "scodoc7_id", ), filter_dept=True, sortkey="nom", diff --git a/app/scodoc/sco_formsemestre.py b/app/scodoc/sco_formsemestre.py index fe4e8e53..65d5d1dd 100644 --- a/app/scodoc/sco_formsemestre.py +++ b/app/scodoc/sco_formsemestre.py @@ -68,7 +68,6 @@ _formsemestreEditor = ndb.EditableTable( "ens_can_edit_eval", "elt_sem_apo", "elt_annee_apo", - "scodoc7_id", ), filter_dept=True, sortkey="date_debut", diff --git a/app/scodoc/sco_semset.py b/app/scodoc/sco_semset.py index 427af387..23a4c6e2 100644 --- a/app/scodoc/sco_semset.py +++ b/app/scodoc/sco_semset.py @@ -418,7 +418,7 @@ def do_semset_remove_sem(semset_id, formsemestre_id): # ---------------------------------------- -def semset_page(format="html", REQUEST=None): +def semset_page(format="html"): """Page avec liste semsets: Table avec : date_debut date_fin titre liste des semestres """ diff --git a/scodoc.py b/scodoc.py index b5176c25..dd7e3f11 100755 --- a/scodoc.py +++ b/scodoc.py @@ -282,12 +282,20 @@ def import_scodoc7_users(): # import-scodoc7-users @click.argument("dept") @click.argument("dept_db_name") @with_appcontext -def import_scodoc7_dept(dept: str, dept_db_name: str): # import-scodoc7-dept +def import_scodoc7_dept(dept: str, dept_db_name: str = ""): # import-scodoc7-dept """Import département ScoDoc 7: dept: InfoComm, dept_db_name: SCOINFOCOMM""" dept_db_uri = f"postgresql:///{dept_db_name}" tools.import_scodoc7_dept(dept, dept_db_uri) +@app.cli.command() +@click.argument("dept", default="") +@with_appcontext +def migrate_scodoc7_dept_archive(dept: str): # migrate-scodoc7-dept-archive + """Post-migration: renomme les archives en fonction des id de ScoDoc 9""" + tools.migrate_scodoc7_dept_archive(dept) + + @app.cli.command() @with_appcontext def clear_cache(): # clear-cache diff --git a/tools/__init__.py b/tools/__init__.py index cf9debf6..599bdf0d 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -6,3 +6,4 @@ from tools.import_scodoc7_user_db import import_scodoc7_user_db from tools.import_scodoc7_dept import import_scodoc7_dept +from tools.migrate_scodoc7_archives import migrate_scodoc7_dept_archive diff --git a/tools/migrate_from_scodoc7.sh b/tools/migrate_from_scodoc7.sh index 537d0be0..67ba70d6 100755 --- a/tools/migrate_from_scodoc7.sh +++ b/tools/migrate_from_scodoc7.sh @@ -204,6 +204,9 @@ do systemctl restart postgresql done +# ----- Post-Migration: renomme archives en fonction des nouveaux ids +su -c "(cd $SCODOC_DIR && source venv/bin/activate && flask migrate-scodoc7-dept-archive)" "$SCODOC_USER" || die "Erreur de la post-migration des archives" + # --- Si migration "en place", désactive ScoDoc 7 if [ "$INPLACE" == 1 ]