diff --git a/app/models/but_refcomp.py b/app/models/but_refcomp.py
index 73ddf9f7ad..a47bac1bf6 100644
--- a/app/models/but_refcomp.py
+++ b/app/models/but_refcomp.py
@@ -97,6 +97,7 @@ class ApcReferentielCompetences(db.Model, XMLModel):
validations_annee = db.relationship(
"ApcValidationAnnee",
backref="referentiel_competence",
+ cascade="all, delete-orphan", # cascade at ORM level
lazy="dynamic",
)
diff --git a/app/models/but_validations.py b/app/models/but_validations.py
index 539c1239da..7efd3069e5 100644
--- a/app/models/but_validations.py
+++ b/app/models/but_validations.py
@@ -38,8 +38,12 @@ class ApcValidationRCUE(db.Model):
)
"formsemestre origine du RCUE (celui d'où a été émis la validation)"
# Les deux UE associées à ce niveau:
- ue1_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), nullable=False)
- ue2_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), nullable=False)
+ ue1_id = db.Column(
+ db.Integer, db.ForeignKey("notes_ue.id", ondelete="CASCADE"), nullable=False
+ )
+ ue2_id = db.Column(
+ db.Integer, db.ForeignKey("notes_ue.id", ondelete="CASCADE"), nullable=False
+ )
# optionnel, le parcours dans lequel se trouve la compétence:
parcours_id = db.Column(
db.Integer, db.ForeignKey("apc_parcours.id", ondelete="set null"), nullable=True
diff --git a/app/models/etudiants.py b/app/models/etudiants.py
index 17cd213d0f..e20a7b6e71 100644
--- a/app/models/etudiants.py
+++ b/app/models/etudiants.py
@@ -30,15 +30,17 @@ class Identite(db.Model, models.ScoDocModel):
id = db.Column(db.Integer, primary_key=True)
etudid = db.synonym("id")
- admission_id = db.Column(db.Integer, db.ForeignKey("admissions.id"), nullable=True)
+ # ForeignKey ondelete set the cascade at the database level
+ admission_id = db.Column(
+ db.Integer, db.ForeignKey("admissions.id", ondelete="CASCADE"), nullable=True
+ )
admission = db.relationship(
"Admission",
back_populates="etud",
uselist=False,
- cascade="all,delete",
+ cascade="all,delete", # cascade also defined at ORM level
single_parent=True,
)
-
dept_id = db.Column(
db.Integer, db.ForeignKey("departement.id"), index=True, nullable=False
)
@@ -147,7 +149,7 @@ class Identite(db.Model, models.ScoDocModel):
> 0
):
raise ScoValueError(
- """clonage étudiant: un étudiant de même code existe déjà
+ """clonage étudiant: un étudiant de même code existe déjà
dans le département destination"""
)
d = dict(self.__dict__)
diff --git a/app/scodoc/sco_dept.py b/app/scodoc/sco_dept.py
index 8e7fc1ef0a..189a871576 100644
--- a/app/scodoc/sco_dept.py
+++ b/app/scodoc/sco_dept.py
@@ -28,11 +28,12 @@
"""Page accueil département (liste des semestres, etc)
"""
-from flask import g, request
+from flask import g
from flask import url_for
from flask_login import current_user
import app
+from app import log
from app.models import ScolarNews
import app.scodoc.sco_utils as scu
from app.scodoc.gen_tables import GenTable
@@ -99,7 +100,7 @@ def index_html(showcodes=0, showsemtable=0):
"""
%(tmpcode)s
- %(lockimg)s %(groupicon)s |
+ %(lockimg)s %(groupicon)s |
%(mois_debut)s - %(mois_fin)s |
%(titre_num)s
(%(responsable_name)s)
@@ -269,9 +270,9 @@ def _sem_table_gt(sems, showcodes=False):
html_class=html_class,
html_sortable=True,
html_table_attrs=f"""
- data-apo_save_url="{url_for('notes.formsemestre_set_apo_etapes', scodoc_dept=g.scodoc_dept)}"
- data-elt_annee_apo_save_url="{url_for('notes.formsemestre_set_elt_annee_apo', scodoc_dept=g.scodoc_dept)}"
- data-elt_sem_apo_save_url="{url_for('notes.formsemestre_set_elt_sem_apo', scodoc_dept=g.scodoc_dept)}"
+ data-apo_save_url="{url_for('notes.formsemestre_set_apo_etapes', scodoc_dept=g.scodoc_dept)}"
+ data-elt_annee_apo_save_url="{url_for('notes.formsemestre_set_elt_annee_apo', scodoc_dept=g.scodoc_dept)}"
+ data-elt_sem_apo_save_url="{url_for('notes.formsemestre_set_elt_sem_apo', scodoc_dept=g.scodoc_dept)}"
""",
html_with_td_classes=True,
preferences=sco_preferences.SemPreferences(),
@@ -329,12 +330,16 @@ def delete_dept(dept_id: int) -> str:
# 1- Create temp tables to store ids
reqs = [
"create temp table etudids_temp as select id from identite where dept_id = %(dept_id)s",
- "create temp table formsemestres_temp as select id from notes_formsemestre where dept_id = %(dept_id)s",
- "create temp table moduleimpls_temp as select id from notes_moduleimpl where formsemestre_id in (select id from formsemestres_temp)",
- "create temp table formations_temp as select id from notes_formations where dept_id = %(dept_id)s",
+ """create temp table formsemestres_temp as select id
+ from notes_formsemestre where dept_id = %(dept_id)s""",
+ """create temp table moduleimpls_temp as select id from notes_moduleimpl
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """create temp table formations_temp as
+ select id from notes_formations where dept_id = %(dept_id)s""",
"create temp table tags_temp as select id from notes_tags where dept_id = %(dept_id)s",
]
for r in reqs:
+ log(f"delete_dept: {r}")
cursor.execute(r, {"dept_id": dept_id})
# 2- Delete student-related informations
@@ -342,7 +347,6 @@ def delete_dept(dept_id: int) -> str:
etud_tables = [
"notes_notes",
"group_membership",
- "admissions",
"billet_absence",
"adresse",
"absences",
@@ -357,29 +361,45 @@ def delete_dept(dept_id: int) -> str:
"scolar_events",
]
for table in etud_tables:
+ log(f"delete from {table}")
cursor.execute(
f"delete from {table} where etudid in (select id from etudids_temp)"
)
reqs = [
+ """delete from apc_validation_annee where referentiel_competence_id
+ in (select id from apc_referentiel_competences where dept_id = %(dept_id)s)""",
"delete from apc_referentiel_competences where dept_id = %(dept_id)s",
- "delete from identite where dept_id = %(dept_id)s",
"delete from sco_prefs where dept_id = %(dept_id)s",
- "delete from notes_semset_formsemestre where formsemestre_id in (select id from formsemestres_temp)",
- "delete from notes_evaluation where moduleimpl_id in (select id from moduleimpls_temp)",
- "delete from notes_modules_enseignants where moduleimpl_id in (select id from moduleimpls_temp)",
- "delete from notes_formsemestre_uecoef where formsemestre_id in (select id from formsemestres_temp)",
- "delete from notes_formsemestre_ue_computation_expr where formsemestre_id in (select id from formsemestres_temp)",
- "delete from notes_formsemestre_responsables where formsemestre_id in (select id from formsemestres_temp)",
- "delete from notes_moduleimpl where formsemestre_id in (select id from formsemestres_temp)",
- "delete from notes_modules_tags where tag_id in (select id from tags_temp)",
+ """delete from notes_semset_formsemestre
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """delete from notes_evaluation
+ where moduleimpl_id in (select id from moduleimpls_temp)""",
+ """delete from notes_modules_enseignants
+ where moduleimpl_id in (select id from moduleimpls_temp)""",
+ """delete from notes_formsemestre_uecoef
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """delete from notes_formsemestre_ue_computation_expr
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """delete from notes_formsemestre_responsables
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """delete from notes_moduleimpl
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """delete from notes_modules_tags
+ where tag_id in (select id from tags_temp)""",
"delete from notes_tags where dept_id = %(dept_id)s",
"delete from notes_modules where formation_id in (select id from formations_temp)",
- "delete from notes_matieres where ue_id in (select id from notes_ue where formation_id in (select id from formations_temp))",
- "delete from notes_formsemestre_etapes where formsemestre_id in (select id from formsemestres_temp)",
- "delete from group_descr where partition_id in (select id from partition where formsemestre_id in (select id from formsemestres_temp))",
+ """delete from notes_matieres
+ where ue_id in (select id from notes_ue
+ where formation_id in (select id from formations_temp))""",
+ """delete from notes_formsemestre_etapes
+ where formsemestre_id in (select id from formsemestres_temp)""",
+ """delete from group_descr where partition_id in
+ (select id from partition
+ where formsemestre_id in (select id from formsemestres_temp))""",
"delete from partition where formsemestre_id in (select id from formsemestres_temp)",
- "delete from notes_formsemestre_custommenu where formsemestre_id in (select id from formsemestres_temp)",
+ """delete from notes_formsemestre_custommenu
+ where formsemestre_id in (select id from formsemestres_temp)""",
"delete from notes_ue where formation_id in (select id from formations_temp)",
"delete from notes_formsemestre where dept_id = %(dept_id)s",
"delete from scolar_news where dept_id = %(dept_id)s",
@@ -393,6 +413,7 @@ def delete_dept(dept_id: int) -> str:
"drop table formsemestres_temp",
]
for r in reqs:
+ log(f"delete_dept: {r}")
cursor.execute(r, {"dept_id": dept_id})
except Exception as e:
cnx.rollback()
diff --git a/app/scodoc/sco_import_etuds.py b/app/scodoc/sco_import_etuds.py
index 05e58ecc31..4cd7cca581 100644
--- a/app/scodoc/sco_import_etuds.py
+++ b/app/scodoc/sco_import_etuds.py
@@ -367,7 +367,7 @@ def scolars_import_excel_file(
val = input_civilite(val)
except ScoValueError as exc:
raise ScoValueError(
- f"""valeur invalide pour 'civilite'
+ f"""valeur invalide pour 'civilite'
(doit etre 'M', 'F', ou 'MME', 'H', 'X' mais pas '{
val}') ligne {linenum}, colonne {titleslist[i]}"""
) from exc
@@ -376,7 +376,7 @@ def scolars_import_excel_file(
val = input_civilite_etat_civil(val)
except ScoValueError as exc:
raise ScoValueError(
- f"""valeur invalide pour 'civilite'
+ f"""valeur invalide pour 'civilite'
(doit etre 'M', 'F', vide ou 'MME', 'H', 'X' mais pas '{
val}') ligne {linenum}, colonne {titleslist[i]}"""
) from exc
@@ -464,9 +464,6 @@ def scolars_import_excel_file(
cursor.execute(
"delete from adresse where etudid=%(etudid)s", {"etudid": etudid}
)
- cursor.execute(
- "delete from admissions where etudid=%(etudid)s", {"etudid": etudid}
- )
cursor.execute(
"delete from group_membership where etudid=%(etudid)s",
{"etudid": etudid},
diff --git a/app/scodoc/sco_synchro_etuds.py b/app/scodoc/sco_synchro_etuds.py
index 3f3a691e9b..e220b84311 100644
--- a/app/scodoc/sco_synchro_etuds.py
+++ b/app/scodoc/sco_synchro_etuds.py
@@ -696,9 +696,6 @@ def do_import_etuds_from_portal(sem, a_importer, etudsapo_ident):
cursor.execute(
"delete from adresse where etudid=%(etudid)s", {"etudid": etudid}
)
- cursor.execute(
- "delete from admissions where etudid=%(etudid)s", {"etudid": etudid}
- )
cursor.execute(
"delete from group_membership where etudid=%(etudid)s",
{"etudid": etudid},
diff --git a/app/views/scolar.py b/app/views/scolar.py
index 7ea499124e..02cd298404 100644
--- a/app/views/scolar.py
+++ b/app/views/scolar.py
@@ -1149,7 +1149,7 @@ def _form_dem_of_def(
return f"""
{header}
{operation_name} de {etud.nomprenom} ({formsemestre.titre_mois()})
-
+
|