Assiduité : fix préférence limite année

This commit is contained in:
Iziram 2024-02-27 15:06:31 +01:00
parent 9dcaf70e18
commit c2e77846b9

View File

@ -3,15 +3,23 @@ from datetime import datetime
from flask import url_for from flask import url_for
from flask_login import current_user from flask_login import current_user
from flask_sqlalchemy.query import Query 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 import db, g
from app.auth.models import User from app.auth.models import User
from app.models import Assiduite, Identite, Justificatif 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.tables import table_builder as tb
from app.scodoc.sco_cache import RequeteTableauAssiduiteCache from app.scodoc.sco_cache import RequeteTableauAssiduiteCache
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_preferences import get_preference
class Pagination: class Pagination:
@ -195,6 +203,17 @@ class ListeAssiJusti(tb.Table):
r = query_finale.all() r = query_finale.all()
RequeteTableauAssiduiteCache.set(cle_cache, r) 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 # Paginer la requête pour ne pas envoyer trop d'informations au client
pagination: Pagination = self.paginer(r, no_pagination=self.no_pagination) pagination: Pagination = self.paginer(r, no_pagination=self.no_pagination)
self.total_pages = pagination.total_pages self.total_pages = pagination.total_pages
@ -637,7 +656,7 @@ class AssiFiltre:
type_filtrage, date = val_filtre type_filtrage, date = val_filtre
match (type_filtrage): match type_filtrage:
# On garde uniquement les dates supérieures au filtre # On garde uniquement les dates supérieures au filtre
case 2: case 2:
query_filtree = query_filtree.filter( query_filtree = query_filtree.filter(