Preparation évol. sco_preferences

This commit is contained in:
Emmanuel Viennet 2022-05-05 18:09:32 +02:00
parent b740f40389
commit 69e6b045db

View File

@ -132,9 +132,12 @@ def clear_base_preferences():
g._SCO_BASE_PREFERENCES = {} # { dept_id: BasePreferences instance } g._SCO_BASE_PREFERENCES = {} # { dept_id: BasePreferences instance }
def get_base_preferences(): def get_base_preferences(dept_id: int = None):
"""Return global preferences for the current department""" """Return global preferences for the specified department
dept_id = g.scodoc_dept_id or the current departement
"""
if dept_id is None:
dept_id = g.scodoc_dept_id
if not hasattr(g, "_SCO_BASE_PREFERENCES"): if not hasattr(g, "_SCO_BASE_PREFERENCES"):
g._SCO_BASE_PREFERENCES = {} g._SCO_BASE_PREFERENCES = {}
if not dept_id in g._SCO_BASE_PREFERENCES: if not dept_id in g._SCO_BASE_PREFERENCES:
@ -142,12 +145,12 @@ def get_base_preferences():
return g._SCO_BASE_PREFERENCES[dept_id] return g._SCO_BASE_PREFERENCES[dept_id]
def get_preference(name, formsemestre_id=None): def get_preference(name, formsemestre_id=None, dept_id=None):
"""Returns value of named preference. """Returns value of named preference.
All preferences have a sensible default value, so this All preferences have a sensible default value, so this
function always returns a usable value for all defined preferences names. function always returns a usable value for all defined preferences names.
""" """
return get_base_preferences().get(formsemestre_id, name) return get_base_preferences(dept_id=dept_id).get(formsemestre_id, name)
def _convert_pref_type(p, pref_spec): def _convert_pref_type(p, pref_spec):
@ -2145,9 +2148,9 @@ class BasePreferences(object):
class SemPreferences: class SemPreferences:
"""Preferences for a formsemestre""" """Preferences for a formsemestre"""
def __init__(self, formsemestre_id=None): def __init__(self, formsemestre_id=None, dept_id=None):
self.formsemestre_id = formsemestre_id self.formsemestre_id = formsemestre_id
self.base_prefs = get_base_preferences() self.base_prefs = get_base_preferences(dept_id=dept_id)
def __getitem__(self, name): def __getitem__(self, name):
return self.base_prefs.get(self.formsemestre_id, name) return self.base_prefs.get(self.formsemestre_id, name)