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

62 lines
2.4 KiB
Python
Raw Normal View History

2022-01-07 15:10:37 +01:00
##############################################################################
# ScoDoc
2023-01-02 13:16:27 +01:00
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
2022-01-07 15:10:37 +01:00
# See LICENSE
##############################################################################
"""Chargement des résultats de semestres (tous types)
2022-01-07 15:10:37 +01:00
"""
from flask import g
from app import db
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
from app.scodoc import sco_cache
2022-01-07 15:10:37 +01:00
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.
"""
is_apc = formsemestre.formation.is_apc()
if is_apc and formsemestre.semestre_id == -1:
formsemestre.semestre_id = 1
db.session.add(formsemestre)
db.session.commit()
sco_cache.invalidate_formsemestre(formsemestre.id)
2022-01-07 15:10:37 +01:00
# --- 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 = {}
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 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)
2022-07-11 18:31:58 +02:00
If not in cache, build it and cache it (in g).
2022-02-06 16:09:17 +01:00
"""
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]