from app import db from app.models import Justificatif, Assiduite, Departement from app.scodoc.sco_archives_justificatifs import JustificatifArchiver from app.scodoc.sco_utils import ProgressBarColors def downgrade_module( dept: str = None, assiduites: bool = False, justificatifs: bool = False ): dept_etudid: list[int] = None dept_id: int = None if dept is not None: departement: Departement = Departement.query.filter_by(acronym=dept).first() assert departement is not None, "Le département n'existe pas." dept_etudid = [etud.id for etud in departement.etudiants] dept_id = departement.id if assiduites: _remove_assiduites(dept_etudid) if justificatifs: _remove_justificatifs(dept_etudid) _remove_justificatifs_archive(dept_id) db.session.commit() print( f"{ProgressBarColors.GREEN}Le module assiduité a bien été remis à zero.{ProgressBarColors.RESET}" ) def _remove_assiduites(dept_etudid: str = None): if dept_etudid is None: Assiduite.query.delete() else: Assiduite.query.filter(Assiduite.etudid.in_(dept_etudid)).delete() def _remove_justificatifs(dept_etudid: str = None): if dept_etudid is None: Justificatif.query.delete() else: Justificatif.query.filter(Justificatif.etudid.in_(dept_etudid)).delete() def _remove_justificatifs_archive(dept_id: int = None): JustificatifArchiver().remove_dept_archive(dept_id)