diff --git a/app/scodoc/sco_archives_justificatifs.py b/app/scodoc/sco_archives_justificatifs.py index 14a779bf8b..c6dbd4472b 100644 --- a/app/scodoc/sco_archives_justificatifs.py +++ b/app/scodoc/sco_archives_justificatifs.py @@ -12,11 +12,14 @@ from app.scodoc.sco_archives import BaseArchiver from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_utils import is_iso_formated +from app import log + class Trace: """gestionnaire de la trace des fichiers justificatifs""" def __init__(self, path: str) -> None: + log(f"init Trace {path}") self.path: str = path + "/_trace.csv" self.content: dict[str, list[datetime, datetime, str]] = {} self.import_from_file() @@ -45,7 +48,7 @@ class Trace: if fname in modes: continue traced: list[datetime, datetime, str] = self.content.get(fname, False) - if not traced: + if not traced or mode == "entry": self.content[fname] = [None, None, None] traced = self.content[fname] @@ -123,8 +126,8 @@ class JustificatifArchiver(BaseArchiver): ) fname: str = self.store(archive_id, filename, data, dept_id=etud.dept_id) - - trace = Trace(self.get_obj_dir(etud.id, dept_id=etud.dept_id)) + log(f"obj_dir {self.get_obj_dir(etud.id, dept_id=etud.dept_id)} | {archive_id}") + trace = Trace(archive_id) trace.set_trace(fname, mode="entry") if user_id is not None: trace.set_trace(fname, mode="user_id", current_user=user_id) @@ -162,13 +165,13 @@ class JustificatifArchiver(BaseArchiver): if os.path.isfile(path): if has_trace: - trace = Trace(self.get_obj_dir(etud.id, dept_id=etud.dept_id)) + trace = Trace(archive_id) trace.set_trace(filename, mode="delete") os.remove(path) else: if has_trace: - trace = Trace(self.get_obj_dir(etud.id, dept_id=etud.dept_id)) + trace = Trace(archive_id) trace.set_trace( *self.list_archive(archive_id, dept_id=etud.dept_id), mode="delete" ) @@ -190,7 +193,7 @@ class JustificatifArchiver(BaseArchiver): archive_id = self.get_id_from_name(etud.id, archive_name, dept_id=etud.dept_id) filenames = self.list_archive(archive_id, dept_id=etud.dept_id) - trace: Trace = Trace(self.get_obj_dir(etud.id, dept_id=etud.dept_id)) + trace: Trace = Trace(archive_id) traced = trace.get_trace(filenames) retour = [(key, value[2]) for key, value in traced.items()] @@ -222,10 +225,3 @@ class JustificatifArchiver(BaseArchiver): rmtree(self.root, ignore_errors=True) else: rmtree(os.path.join(self.root, str(dept_id)), ignore_errors=True) - - def get_trace( # XXX inutilisée ? - self, etud: Identite, *fnames: str - ) -> dict[str, list[datetime, datetime]]: - """Récupère la trace des justificatifs de l'étudiant""" - trace = Trace(self.get_obj_dir(etud.id, etud.dept_id)) - return trace.get_trace(fnames) diff --git a/app/templates/assiduites/pages/ajout_justificatif.j2 b/app/templates/assiduites/pages/ajout_justificatif.j2 index 19e512fd9d..bef71862ff 100644 --- a/app/templates/assiduites/pages/ajout_justificatif.j2 +++ b/app/templates/assiduites/pages/ajout_justificatif.j2 @@ -8,7 +8,7 @@ {% include "assiduites/widgets/tableau_justi.j2" %} -
+
@@ -130,7 +130,7 @@ } function fieldsToJustificatif() { - const field = document.querySelector('.justi-form') + const field = document.querySelector('.justi-form.page') const { deb, fin } = getDates() @@ -230,9 +230,9 @@ } function getDates() { - if (document.getElementById('justi_journee').checked) { - const date_str_deb = document.getElementById("justi_date_debut").value - const date_str_fin = document.getElementById("justi_date_debut").value + if (document.querySelector('.page #justi_journee').checked) { + const date_str_deb = document.querySelector(".page #justi_date_debut").value + const date_str_fin = document.querySelector(".page #justi_date_debut").value @@ -243,8 +243,8 @@ } return { - "deb": document.getElementById("justi_date_debut").value, - "fin": document.getElementById("justi_date_fin").value, + "deb": document.querySelector(".page #justi_date_debut").value, + "fin": document.querySelector(".page #justi_date_fin").value, } } diff --git a/app/templates/assiduites/widgets/differee.j2 b/app/templates/assiduites/widgets/differee.j2 index 523c4a8270..33e5356a3d 100644 --- a/app/templates/assiduites/widgets/differee.j2 +++ b/app/templates/assiduites/widgets/differee.j2 @@ -96,6 +96,14 @@ display: flex; } + .td[assiduite_id='insc'] * { + display: none; + } + + .td[assiduite_id='insc']::after { + content: "Etudiant non inscrit"; + } + .sticky { position: sticky; left: 0; @@ -278,6 +286,8 @@ currentDate = moment(currentDate).tz(TIMEZONE).format("YYYY-MM-DDTHH:mm"); } + const inscriptionsModule = {}; + function createColumn(dateStart = "", dateEnd = "", moduleimpl_id = "") { let table = document.getElementById("studentTable"); let th = document.createElement("div"); @@ -561,6 +571,8 @@ const d_debut = moment(inputDeb).tz(TIMEZONE); const d_fin = moment(inputFin).tz(TIMEZONE); + const moduleimpl_id = col.querySelector("#moduleimpl_select").value; + const periode = { deb: d_debut, fin: d_fin, @@ -573,9 +585,12 @@ }); setEtatLine(td, "") const etu = td.parentElement.getAttribute('etudid'); + const inscriptionModule = ["", "autre"].indexOf(moduleimpl_id) !== -1 ? true : checkInscriptionModule(moduleimpl_id, etu); const conflits = getAssiduitesConflict(etu, periode); - - if (conflits.length == 0) { + if (!inscriptionModule) { + td.setAttribute('assiduite_id', "insc"); + } + else if (conflits.length == 0) { td.setAttribute('assiduite_id', "-1"); } else if (conflits.length == 1 && isConflictSameAsPeriod(conflits[0], periode)) { const assi = conflits[0]; @@ -587,7 +602,6 @@ const inputs = [...td.querySelectorAll('input')]; inputs.forEach((i) => { i.disabled = true; - }) } }) @@ -871,7 +885,7 @@ const { moduleimpl, deb, fin } = getAssiduitesCol(colid, false); const lines = [...document.querySelectorAll(`[assiduite_id][colid='${colid}']`)].filter((el) => { - return el.getAttribute('assiduite_id') != "conflit"; + return ["conflit", "insc"].indexOf(el.getAttribute('assiduite_id')) == -1; }) const toCreate = lines.filter((el) => { return el.getAttribute('assiduite_id') == '-1' }) @@ -1019,6 +1033,25 @@ }) } + function checkInscriptionModule(moduleimpl_id, etudid) { + if (!inscriptionsModule.hasOwnProperty(moduleimpl_id)) { + const path = getUrl() + `/api/moduleimpl/${moduleimpl_id}/inscriptions`; + sync_get( + path, + (data, status) => { + inscriptionsModule[moduleimpl_id] = data; + }, + (data, status) => { + //error + console.error(data, status); + errorAlert(); + } + ); + } + const etudsInscrits = inscriptionsModule[moduleimpl_id].map((i) => i.etudid); + return etudsInscrits.indexOf(Number(etudid)) !== -1; + } + window.addEventListener('load', () => { document.getElementById("addColumn").addEventListener("click", () => { createColumn();