1
0
forked from ScoDoc/ScoDoc
ScoDoc/app/comp/res_sem.py

57 lines
2.2 KiB
Python
Raw Normal View History

2022-01-07 15:10:37 +01:00
##############################################################################
# ScoDoc
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
# See LICENSE
##############################################################################
"""Chargement des résultats de semestres (tous types)
2022-01-07 15:10:37 +01:00
"""
from flask import g
2022-02-06 16:09:17 +01:00
from app.comp.jury import ValidationsSemestre
2022-01-07 15:10:37 +01:00
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
2022-02-06 16:09:17 +01:00
def load_formsemestre_results(formsemestre: FormSemestre) -> ResultatsSemestre:
2022-01-07 15:10:37 +01:00
"""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)
If not in cache, build it and cache it.
"""
# --- Try local cache (within the same request context)
2022-02-06 16:09:17 +01:00
if not hasattr(g, "formsemestre_results_cache"):
g.formsemestre_results_cache = {} # pylint: disable=C0237
2022-01-07 15:10:37 +01:00
else:
2022-02-06 16:09:17 +01:00
if formsemestre.id in g.formsemestre_results_cache:
return g.formsemestre_results_cache[formsemestre.id]
2022-01-07 15:10:37 +01:00
klass = (
ResultatsSemestreBUT
if formsemestre.formation.is_apc()
else ResultatsSemestreClassic
)
2022-02-06 16:09:17 +01:00
g.formsemestre_results_cache[formsemestre.id] = klass(formsemestre)
return g.formsemestre_results_cache[formsemestre.id]
def load_formsemestre_validations(formsemestre: FormSemestre) -> ValidationsSemestre:
"""Charge les résultats de jury de ce semestre.
Search in local cache (g.formsemestre_result_cache)
If not in cache, build it and cache it.
"""
if not hasattr(g, "formsemestre_validation_cache"):
g.formsemestre_validations_cache = {} # pylint: disable=C0237
else:
if formsemestre.id in g.formsemestre_validations_cache:
return g.formsemestre_validations_cache[formsemestre.id]
g.formsemestre_validations_cache[formsemestre.id] = ValidationsSemestre(
formsemestre
)
return g.formsemestre_validations_cache[formsemestre.id]