From 0fa1fa36e2310c77352ffb4d910868e32b2c74cb Mon Sep 17 00:00:00 2001 From: Iziram Date: Thu, 21 Sep 2023 18:44:38 +0200 Subject: [PATCH] Assiduites : fix trace justificatifs --- app/scodoc/sco_archives_justificatifs.py | 22 ++++++++----------- .../assiduites/pages/ajout_justificatif.j2 | 14 ++++++------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/scodoc/sco_archives_justificatifs.py b/app/scodoc/sco_archives_justificatifs.py index 14a779bf8..c6dbd4472 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 19e512fd9..bef71862f 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, } }