Assiduites : fix trace justificatifs

This commit is contained in:
Iziram 2023-09-21 18:44:38 +02:00
parent b8f7037804
commit 0fa1fa36e2
2 changed files with 16 additions and 20 deletions

View File

@ -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)

View File

@ -8,7 +8,7 @@
{% include "assiduites/widgets/tableau_justi.j2" %}
</section>
<section class="justi-form">
<section class="justi-form page">
<fieldset>
<div class="justi-row">
@ -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,
}
}