chargement resultats semestres

This commit is contained in:
Emmanuel Viennet 2022-01-07 15:10:37 +01:00
parent da1a2ccf43
commit 5e144d8745

34
app/comp/sco_sem.py Normal file
View File

@ -0,0 +1,34 @@
##############################################################################
# ScoDoc
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
# See LICENSE
##############################################################################
"""Chargement des résultats de semestres (tous types))
"""
from flask import g
from app.comp.res_common import ResultatsSemestre
from app.comp.res_classic import ResultatsSemestreClassic
from app.comp.res_but import ResultatsSemestreBUT
from app.models.formsemestre import FormSemestre
def load_formsemestre_result(formsemestre: FormSemestre) -> ResultatsSemestre:
"""Returns ResultatsSemestre for this formsemestre.
Suivant le type de formation, retour une instance de
ResultatsSemestreClassic ou de ResultatsSemestreBUT.
Search in local cache (g.formsemestre_result_cache)
then global app cache (eg REDIS)
If not in cache, build it and cache it.
"""
# --- Try local cache (within the same request context)
if not hasattr(g, "formsemestre_result_cache"):
g.formsemestre_result_cache = {}
else:
if formsemestre.id in g.formsemestre_result_cache:
return g.formsemestre_result_cache[formsemestre.id]
klass = ResultatsSemestreBUT if formsemestre.is_apc() else ResultatsSemestreClassic
return klass(formsemestre)