From 5e144d87450b73c27a70428d9994ec39a7fc7453 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 7 Jan 2022 15:10:37 +0100 Subject: [PATCH] chargement resultats semestres --- app/comp/sco_sem.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/comp/sco_sem.py diff --git a/app/comp/sco_sem.py b/app/comp/sco_sem.py new file mode 100644 index 000000000..44f140a33 --- /dev/null +++ b/app/comp/sco_sem.py @@ -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)