From c2e77846b9fa5eb38a6ce4878b8265f4faaa0e35 Mon Sep 17 00:00:00 2001 From: Iziram Date: Tue, 27 Feb 2024 15:06:31 +0100 Subject: [PATCH] =?UTF-8?q?Assiduit=C3=A9=20:=20fix=20pr=C3=A9f=C3=A9rence?= =?UTF-8?q?=20limite=20ann=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/tables/liste_assiduites.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/tables/liste_assiduites.py b/app/tables/liste_assiduites.py index c720fac7..2d1de9e6 100644 --- a/app/tables/liste_assiduites.py +++ b/app/tables/liste_assiduites.py @@ -3,15 +3,23 @@ from datetime import datetime from flask import url_for from flask_login import current_user from flask_sqlalchemy.query import Query -from sqlalchemy import desc, literal, union, asc +from sqlalchemy import desc, literal, literal_column, union, asc from app import db, g from app.auth.models import User from app.models import Assiduite, Identite, Justificatif -from app.scodoc.sco_utils import EtatAssiduite, EtatJustificatif, to_bool +from app.scodoc.sco_utils import ( + EtatAssiduite, + EtatJustificatif, + to_bool, + date_debut_annee_scolaire, + date_fin_annee_scolaire, + localize_datetime, +) from app.tables import table_builder as tb from app.scodoc.sco_cache import RequeteTableauAssiduiteCache from app.scodoc.sco_permissions import Permission +from app.scodoc.sco_preferences import get_preference class Pagination: @@ -195,6 +203,17 @@ class ListeAssiJusti(tb.Table): r = query_finale.all() RequeteTableauAssiduiteCache.set(cle_cache, r) + # Filtrer Si préférence "Limiter les assiduités à l'année courante" + if get_preference("assi_limit_annee"): + annee_debut = localize_datetime(date_debut_annee_scolaire()) + annee_fin = localize_datetime(date_fin_annee_scolaire()) + r = [ + obj + for obj in r + if obj._asdict()["date_debut"] >= annee_debut + and obj._asdict()["date_fin"] <= annee_fin + ] + # Paginer la requête pour ne pas envoyer trop d'informations au client pagination: Pagination = self.paginer(r, no_pagination=self.no_pagination) self.total_pages = pagination.total_pages @@ -637,7 +656,7 @@ class AssiFiltre: type_filtrage, date = val_filtre - match (type_filtrage): + match type_filtrage: # On garde uniquement les dates supérieures au filtre case 2: query_filtree = query_filtree.filter(