From 0383b82597b00eb33d7b78d99d82dbf29b5bfdf6 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 12 Feb 2022 12:23:53 +0100 Subject: [PATCH] Fix minimal pour #304 --- app/scodoc/sco_preferences.py | 28 ++++++++++++++-------------- sco_version.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py index dbbdd0ac5e..6667db96ae 100644 --- a/app/scodoc/sco_preferences.py +++ b/app/scodoc/sco_preferences.py @@ -68,17 +68,17 @@ des tuples (name, value, formsemestre_id). Si formsemestre_id est NULL, la valeur concerne tous les semestres, sinon, elle ne concerne que le semestre indiqué. -* Utilisation dans ScoDoc8 +* Utilisation dans ScoDoc 9 - lire une valeur: get_preference(name, formsemestre_id) nb: les valeurs sont des chaines, sauf: - . si le type est spécfié (float ou int) + . si le type est spécifié (float ou int) . les boolcheckbox qui sont des entiers 0 ou 1 - avoir un mapping (read only) de toutes les valeurs: sco_preferences.SemPreferences(formsemestre_id) - - editer les preferences globales: + - éditer les preferences globales: sco_preferences.get_base_preferences(self).edit() - - editer les preferences d'un semestre: + - éditer les preferences d'un semestre: SemPreferences(formsemestre_id).edit() * Implémentation: sco_preferences.py @@ -123,22 +123,22 @@ from app.scodoc.TrivialFormulator import TrivialFormulator import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu -_SCO_BASE_PREFERENCES = {} # { dept_acronym: BasePreferences instance } - def clear_base_preferences(): """Clear cached preferences""" # usefull only for tests, where the same process may run # successively on several databases - _SCO_BASE_PREFERENCES.clear() + g._SCO_BASE_PREFERENCES = {} # { dept_id: BasePreferences instance } def get_base_preferences(): """Return global preferences for the current department""" - dept_acronym = g.scodoc_dept - if not dept_acronym in _SCO_BASE_PREFERENCES: - _SCO_BASE_PREFERENCES[dept_acronym] = BasePreferences(dept_acronym) - return _SCO_BASE_PREFERENCES[dept_acronym] + dept_id = g.scodoc_dept_id + if not hasattr(g, "_SCO_BASE_PREFERENCES"): + g._SCO_BASE_PREFERENCES = {} + if not dept_id in g._SCO_BASE_PREFERENCES: + g._SCO_BASE_PREFERENCES[dept_id] = BasePreferences(dept_id) + return g._SCO_BASE_PREFERENCES[dept_id] def get_preference(name, formsemestre_id=None): @@ -263,10 +263,10 @@ class BasePreferences(object): filter_nulls=False, ) - def __init__(self, dept_acronym: str): - dept = Departement.query.filter_by(acronym=dept_acronym).first() + def __init__(self, dept_id: int): + dept = Departement.query.get(dept_id) if not dept: - raise ScoValueError(f"Invalid departement: {dept_acronym}") + raise ScoValueError(f"Invalid departement: {dept_id}") self.dept_id = dept.id self.init() self.load() diff --git a/sco_version.py b/sco_version.py index 28aefc96d3..884506e9d2 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.1.54" +SCOVERSION = "9.2a-54" SCONAME = "ScoDoc"