Corriger la suppression des mails Outlook
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
bfaf470c54
commit
a548612219
1 changed files with 14 additions and 8 deletions
|
|
@ -328,7 +328,7 @@ def data_management():
|
||||||
"""Page de gestion des données : voir et supprimer en masse."""
|
"""Page de gestion des données : voir et supprimer en masse."""
|
||||||
from ..models.maintenance import Intervention
|
from ..models.maintenance import Intervention
|
||||||
from ..models.equipment import Equipment
|
from ..models.equipment import Equipment
|
||||||
from ...outlook.models import OutlookMail, OutlookMailInterpretation
|
from ...outlook.models import OutlookMail, OutlookMailInterpretation, OutlookAttachment
|
||||||
from ...ent.models import EntMessage
|
from ...ent.models import EntMessage
|
||||||
from ...ent.interpretation_models import EntMessageInterpretation
|
from ...ent.interpretation_models import EntMessageInterpretation
|
||||||
|
|
||||||
|
|
@ -442,18 +442,24 @@ def delete_all_interventions():
|
||||||
@admin_required
|
@admin_required
|
||||||
def delete_all_mails():
|
def delete_all_mails():
|
||||||
"""Supprime tous les mails Outlook."""
|
"""Supprime tous les mails Outlook."""
|
||||||
from ...outlook.models import OutlookMail, OutlookMailInterpretation
|
from ...outlook.models import OutlookMail, OutlookMailInterpretation, OutlookAttachment
|
||||||
confirm = request.form.get('confirm_text', '')
|
confirm = request.form.get('confirm_text', '')
|
||||||
if confirm != 'SUPPRIMER':
|
if confirm != 'SUPPRIMER':
|
||||||
flash('Confirmation requise : tapez "SUPPRIMER" dans le champ de confirmation.', 'danger')
|
flash('Confirmation requise : tapez "SUPPRIMER" dans le champ de confirmation.', 'danger')
|
||||||
return redirect(url_for('admin.data_management'))
|
return redirect(url_for('admin.data_management'))
|
||||||
|
|
||||||
# Supprimer d'abord les interpretations
|
try:
|
||||||
OutlookMailInterpretation.query.delete()
|
# Les pièces jointes possèdent une FK vers les mails : elles doivent
|
||||||
# Supprimer les mails
|
# être supprimées avant leurs mails (le modèle seul ne garantit pas
|
||||||
count = OutlookMail.query.count()
|
# une cascade côté MariaDB).
|
||||||
OutlookMail.query.delete()
|
OutlookAttachment.query.delete(synchronize_session=False)
|
||||||
db.session.commit()
|
OutlookMailInterpretation.query.delete(synchronize_session=False)
|
||||||
|
count = OutlookMail.query.count()
|
||||||
|
OutlookMail.query.delete(synchronize_session=False)
|
||||||
|
db.session.commit()
|
||||||
|
except Exception:
|
||||||
|
db.session.rollback()
|
||||||
|
raise
|
||||||
flash(f'{count} mail(s) supprime(s) definitivement.', 'warning')
|
flash(f'{count} mail(s) supprime(s) definitivement.', 'warning')
|
||||||
return redirect(url_for('admin.data_management'))
|
return redirect(url_for('admin.data_management'))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue