forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -427,7 +427,7 @@ def invalidate_assiduites_count(etudid, sem):
|
||||
"""Invalidate (clear) cached counts"""
|
||||
date_debut = sem["date_debut_iso"]
|
||||
date_fin = sem["date_fin_iso"]
|
||||
for met in sco_preferences.ASSIDUITES_METRIC_LABEL.values():
|
||||
for met in [string.lower() for string in scu.AssiduitesMetricShort.all()]:
|
||||
key = str(etudid) + "_" + date_debut + "_" + date_fin + f"{met}_assiduites"
|
||||
sco_cache.AbsSemEtudCache.delete(key)
|
||||
|
||||
|
@ -198,13 +198,6 @@ def _get_pref_default_value_from_config(name, pref_spec):
|
||||
|
||||
_INSTALLED_FONTS = ", ".join(sco_pdf.get_available_font_names())
|
||||
|
||||
ASSIDUITES_METRIC_LABEL = {
|
||||
# l'ordre est important, c'est celui-du menu. Le defaut en 1er donc.
|
||||
"1/2 J.": "demi",
|
||||
"J.": "journee",
|
||||
"H.": "heure",
|
||||
}
|
||||
|
||||
PREF_CATEGORIES = (
|
||||
# sur page "Paramètres"
|
||||
("general", {"title": ""}), # voir paramètre titlr de TrivialFormulator
|
||||
@ -666,8 +659,8 @@ class BasePreferences(object):
|
||||
{
|
||||
"initvalue": "1/2 J.",
|
||||
"input_type": "menu",
|
||||
"labels": list(ASSIDUITES_METRIC_LABEL.keys()),
|
||||
"allowed_values": list(ASSIDUITES_METRIC_LABEL.keys()),
|
||||
"labels": scu.AssiduitesMetrics.LONG,
|
||||
"allowed_values": scu.AssiduitesMetrics.SHORT,
|
||||
"title": "Métrique de l'assiduité",
|
||||
"explanation": "Unité utilisée dans la fiche étudiante, les bilans et les calculs",
|
||||
"category": "assi",
|
||||
|
@ -163,6 +163,11 @@ class BiDirectionalEnum(Enum):
|
||||
"""Vérifie sur un attribut existe dans l'enum"""
|
||||
return attr.upper() in cls._member_names_
|
||||
|
||||
@classmethod
|
||||
def all(cls, keys=True):
|
||||
"""Retourne toutes les clés de l'enum"""
|
||||
return cls._member_names_ if keys else list(cls._value2member_map_.keys())
|
||||
|
||||
@classmethod
|
||||
def get(cls, attr: str, default: any = None):
|
||||
"""Récupère une valeur à partir de son attribut"""
|
||||
@ -251,15 +256,54 @@ def is_period_overlapping(
|
||||
return p_deb < i_fin and p_fin > i_deb
|
||||
|
||||
|
||||
def translate_assiduites_metric(hr_metric) -> str:
|
||||
if hr_metric == "1/2 J.":
|
||||
return "demi"
|
||||
if hr_metric == "J.":
|
||||
return "journee"
|
||||
if hr_metric == "N.":
|
||||
return "compte"
|
||||
if hr_metric == "H.":
|
||||
return "heure"
|
||||
class AssiduitesMetrics:
|
||||
"""Labels associés au métrique de l'assiduité"""
|
||||
|
||||
SHORT: list[str] = ["1/2 J.", "J.", "H."]
|
||||
LONG: list[str] = ["Demi-Journée", "Journée", "Heure"]
|
||||
TAG: list[str] = ["demi", "journee", "heure"]
|
||||
|
||||
|
||||
def translate_assiduites_metric(metric, inverse=True, short=True) -> str:
|
||||
"""
|
||||
translate_assiduites_metric
|
||||
|
||||
SHORT[true] : "J." "H." "N." "1/2 J."
|
||||
SHORT[false] : "Journée" "Heure" "Nombre" "Demi-Journée"
|
||||
|
||||
inverse[false] : "demi" -> "1/2 J."
|
||||
inverse[true] : "1/2 J." -> "demi"
|
||||
|
||||
|
||||
Args:
|
||||
metric (str): la métrique à traduire
|
||||
inverse (bool, optional). Defaults to True.
|
||||
short (bool, optional). Defaults to True.
|
||||
|
||||
Returns:
|
||||
str: la métrique traduite
|
||||
"""
|
||||
index: int = None
|
||||
if not inverse:
|
||||
try:
|
||||
index = AssiduitesMetrics.TAG.index(metric)
|
||||
return (
|
||||
AssiduitesMetrics.SHORT[index]
|
||||
if short
|
||||
else AssiduitesMetrics.LONG[index]
|
||||
)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
try:
|
||||
index = (
|
||||
AssiduitesMetrics.SHORT.index(metric)
|
||||
if short
|
||||
else AssiduitesMetrics.LONG.index(metric)
|
||||
)
|
||||
return AssiduitesMetrics.TAG[index]
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
# Types de modules
|
||||
|
@ -125,8 +125,8 @@ class RowAssi(tb.Row):
|
||||
"absent": ["Absences", 0.0, 0.0],
|
||||
}
|
||||
|
||||
assi_metric = sco_preferences.ASSIDUITES_METRIC_LABEL.get(
|
||||
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id)
|
||||
assi_metric = scu.translate_assiduites_metric(
|
||||
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id),
|
||||
)
|
||||
|
||||
for etat, valeur in retour.items():
|
||||
|
@ -327,8 +327,8 @@ def bilan_etud():
|
||||
date_debut: str = f"{scu.annee_scolaire()}-09-01"
|
||||
date_fin: str = f"{scu.annee_scolaire()+1}-06-30"
|
||||
|
||||
assi_metric = sco_preferences.ASSIDUITES_METRIC_LABEL.get(
|
||||
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id)
|
||||
assi_metric = scu.translate_assiduites_metric(
|
||||
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id),
|
||||
)
|
||||
|
||||
return HTMLBuilder(
|
||||
@ -840,8 +840,14 @@ def visu_assi_group():
|
||||
|
||||
return render_template(
|
||||
"assiduites/pages/visu_assi.j2",
|
||||
assi_metric=sco_preferences.ASSIDUITES_METRIC_LABEL.get(
|
||||
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id)
|
||||
assi_metric=scu.translate_assiduites_metric(
|
||||
scu.translate_assiduites_metric(
|
||||
sco_preferences.get_preference(
|
||||
"assi_metrique", dept_id=g.scodoc_dept_id
|
||||
),
|
||||
),
|
||||
inverse=False,
|
||||
short=False,
|
||||
),
|
||||
date_debut=dates["debut"],
|
||||
date_fin=dates["fin"],
|
||||
|
Loading…
Reference in New Issue
Block a user