From 18908594828fc060746b659eb0becb1e671b2f02 Mon Sep 17 00:00:00 2001 From: iziram Date: Wed, 13 Sep 2023 15:19:21 +0200 Subject: [PATCH] Assiduites : fix Justificatifs en attentes #724 --- app/api/justificatifs.py | 67 +++- app/scodoc/sco_formsemestre_status.py | 5 + app/scodoc/sco_utils.py | 4 +- app/templates/assiduites/pages/bilan_dept.j2 | 13 +- .../assiduites/pages/liste_assiduites.j2 | 4 +- .../assiduites/widgets/tableau_assi.j2 | 181 +++++++++ .../assiduites/widgets/tableau_base.j2 | 343 +----------------- .../assiduites/widgets/tableau_justi.j2 | 192 +++++++++- app/templates/sidebar.j2 | 5 +- app/views/assiduites.py | 18 +- 10 files changed, 470 insertions(+), 362 deletions(-) diff --git a/app/api/justificatifs.py b/app/api/justificatifs.py index e68b397a..f753fc0e 100644 --- a/app/api/justificatifs.py +++ b/app/api/justificatifs.py @@ -19,7 +19,13 @@ from app.api import api_bp as bp from app.api import api_web_bp from app.api import get_model_api_object, tools from app.decorators import permission_required, scodoc -from app.models import Identite, Justificatif, Departement, FormSemestre +from app.models import ( + Identite, + Justificatif, + Departement, + FormSemestre, + FormSemestreInscription, +) from app.models.assiduites import ( compute_assiduites_justified, ) @@ -27,6 +33,7 @@ from app.scodoc.sco_archives_justificatifs import JustificatifArchiver from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_permissions import Permission from app.scodoc.sco_utils import json_error +from app.scodoc.sco_groups import get_group_members # Partie Modèle @@ -145,14 +152,40 @@ def justificatifs_dept(dept_id: int = None, with_query: bool = False): if with_query: justificatifs_query = _filter_manager(request, justificatifs_query) + data_set: list[dict] = [] - for just in justificatifs_query.all(): - data = just.to_dict(format_api=True) - data_set.append(data) + for just in justificatifs_query: + data_set.append(_set_sems_and_groupe(just)) return data_set +def _set_sems_and_groupe(justi: Justificatif) -> dict: + from app.scodoc.sco_groups import get_etud_groups + + data = justi.to_dict(format_api=True) + + formsemestre: FormSemestre = ( + FormSemestre.query.join( + FormSemestreInscription, + FormSemestre.id == FormSemestreInscription.formsemestre_id, + ) + .filter( + justi.date_debut <= FormSemestre.date_fin, + justi.date_fin >= FormSemestre.date_debut, + FormSemestreInscription.etudid == justi.etudid, + ) + .first() + ) + if formsemestre: + data["formsemestre"] = { + "id": formsemestre.id, + "title": formsemestre.session_id(), + } + + return data + + @bp.route( "/justificatifs/formsemestre/", defaults={"with_query": False} ) @@ -732,13 +765,16 @@ def _filter_manager(requested, justificatifs_query): # cas 5 : formsemestre_id formsemestre_id = requested.args.get("formsemestre_id") - if formsemestre_id is not None: + if formsemestre_id not in [None, "", -1]: formsemestre: FormSemestre = None - formsemestre_id = int(formsemestre_id) - formsemestre = FormSemestre.query.filter_by(id=formsemestre_id).first() - justificatifs_query = scass.filter_by_formsemestre( - justificatifs_query, Justificatif, formsemestre - ) + try: + formsemestre_id = int(formsemestre_id) + formsemestre = FormSemestre.query.filter_by(id=formsemestre_id).first() + justificatifs_query = scass.filter_by_formsemestre( + justificatifs_query, Justificatif, formsemestre + ) + except ValueError: + formsemestre = None order = requested.args.get("order", None) if order is not None: @@ -755,4 +791,15 @@ def _filter_manager(requested, justificatifs_query): Justificatif.date_fin <= scu.date_fin_anne_scolaire(annee), ) + group_id = requested.args.get("group_id", None) + if group_id is not None: + try: + group_id = int(group_id) + etudids: list[int] = [etu["etudid"] for etu in get_group_members(group_id)] + justificatifs_query = justificatifs_query.filter( + Justificatif.etudid.in_(etudids) + ) + except ValueError: + group_id = None + return justificatifs_query diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 7e67e4af..c21e8774 100755 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -852,6 +852,11 @@ def _make_listes_sem(formsemestre: FormSemestre, with_absences=True): }?group_ids=%(group_id)s&formsemestre_id={ formsemestre.formsemestre_id }"> + """ else: diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 7cbc3e0d..f92ab38e 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -670,8 +670,8 @@ def AbsencesURL(): def AssiduitesURL(): """URL of Assiduités""" - return url_for("assiduites.index_html", scodoc_dept=g.scodoc_dept)[ - : -len("/index_html") + return url_for("assiduites.bilan_dept", scodoc_dept=g.scodoc_dept)[ + : -len("/BilanDept") ] diff --git a/app/templates/assiduites/pages/bilan_dept.j2 b/app/templates/assiduites/pages/bilan_dept.j2 index 2e8ca5be..3301c85f 100644 --- a/app/templates/assiduites/pages/bilan_dept.j2 +++ b/app/templates/assiduites/pages/bilan_dept.j2 @@ -6,6 +6,7 @@

Justificatifs en attente (ou modifiés)

+ {% include "assiduites/widgets/tableau_justi.j2" %}
@@ -34,14 +35,17 @@ generate(defAnnee) } + let formsemestre_id = "{{formsemestre_id}}" + let group_id = "{{group_id}}" + function getDeptJustificatifsFromPeriod(action) { - const path = getUrl() + `/api/justificatifs/dept/${dept_id}/query?date_debut=${bornes.deb}&date_fin=${bornes.fin}&etat=attente,modifie` + const formsemestre = formsemestre_id ? `&formsemestre_id=${formsemestre_id}` : "" + const group = group_id ? `&group_id=${group_id}` : "" + const path = getUrl() + `/api/justificatifs/dept/${dept_id}/query?date_debut=${bornes.deb}&date_fin=${bornes.fin}&etat=attente,modifie${formsemestre}${group}` async_get( path, (data, status) => { - console.log(data); justificatifCallBack(data); - }, (data, status) => { console.error(data, status) @@ -88,6 +92,7 @@ filterJustificatifs = { "columns": [ + "formsemestre", "etudid", "entry_date", "date_debut", @@ -100,7 +105,7 @@ "etat": [ "attente", "modifie" - ] + ], } } const select = document.querySelector('#annee'); diff --git a/app/templates/assiduites/pages/liste_assiduites.j2 b/app/templates/assiduites/pages/liste_assiduites.j2 index eb1f9ade..aefc644b 100644 --- a/app/templates/assiduites/pages/liste_assiduites.j2 +++ b/app/templates/assiduites/pages/liste_assiduites.j2 @@ -4,10 +4,10 @@

Liste de l'assiduité et des justificatifs de {{sco.etud.nomprenom}}

{% include "assiduites/widgets/tableau_base.j2" %}

Assiduités :

- + {% include "assiduites/widgets/tableau_assi.j2" %}

Justificatifs :

- + {% include "assiduites/widgets/tableau_justi.j2" %}