1
0
forked from ScoDoc/ScoDoc
ScoDoc-Front/app/scodoc/sco_core.py

94 lines
2.9 KiB
Python
Raw Normal View History

2021-05-29 18:22:51 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""essai: ceci serait un module scodoc/sco_xxx.py
2021-05-29 18:22:51 +02:00
"""
import types
import sco_utils as scu
2021-06-13 23:37:14 +02:00
from notes_table import NOTES_CACHE_INST, CacheNotesTable
from scodoc_manager import sco_mgr
from sco_exceptions import ScoInvalidDept
2021-05-29 18:22:51 +02:00
2021-05-29 18:22:51 +02:00
def sco_get_version(context, REQUEST=None):
"""Une fonction typique de ScoDoc7"""
2021-05-29 18:22:51 +02:00
return """<html><body><p>%s</p></body></html>""" % scu.SCOVERSION
def test_refactor(context, x=1):
x = context.toto()
2021-06-13 18:29:53 +02:00
y = ("context=" + sco_edit_module.module_is_locked(context, "alpha")) + "23"
2021-06-13 23:37:14 +02:00
z = html_sco_header.sco_header(
context,
2021-06-12 22:43:22 +02:00
a_long_argument_hahahahaha=1,
another_very_long_arggggggggggggg=2,
z=6,
u=99,
kkkkkk=1,
)
2021-06-13 23:37:14 +02:00
def get_dept_id():
if g.scodoc_dept in sco_mgr.get_dept_ids():
return g.scodoc_dept
raise ScoInvalidDept("département invalide: %s" % g.scodoc_dept)
#
# Cache global: chaque instance, repérée par sa connexion db, a un cache
# qui est recréé à la demande
#
CACHE_formsemestre_inscription = {}
CACHE_evaluations = {}
# cache notes evaluations
def get_evaluations_cache(context):
"""returns cache for evaluations"""
u = context.GetDBConnexionString()
if CACHE_evaluations.has_key(u):
return CACHE_evaluations[u]
else:
log("get_evaluations_cache: new simpleCache")
CACHE_evaluations[u] = sco_cache.simpleCache()
return CACHE_evaluations[u]
def get_notes_cache(context):
"returns CacheNotesTable instance for us"
u = sco_mgr.get_db_uri() # identifie le dept de facon unique
if not NOTES_CACHE_INST.has_key(u):
log("getNotesCache: creating cache for %s" % u)
NOTES_CACHE_INST[u] = CacheNotesTable()
return NOTES_CACHE_INST[u]
def inval_cache(
context, formsemestre_id=None, pdfonly=False, formsemestre_id_list=None
): # >
"expire cache pour un semestre (ou tous si pas d'argument)"
if formsemestre_id_list:
for formsemestre_id in formsemestre_id_list:
get_notes_cache(context).inval_cache(
context, formsemestre_id=formsemestre_id, pdfonly=pdfonly
)
# Affecte aussi cache inscriptions
get_formsemestre_inscription_cache(context).inval_cache(key=formsemestre_id)
else:
get_notes_cache(context).inval_cache(
context, formsemestre_id=formsemestre_id, pdfonly=pdfonly
)
# Affecte aussi cache inscriptions
get_formsemestre_inscription_cache(context).inval_cache(key=formsemestre_id)
# Cache inscriptions semestres
def get_formsemestre_inscription_cache(context, format=None):
u = context.GetDBConnexionString()
if CACHE_formsemestre_inscription.has_key(u):
return CACHE_formsemestre_inscription[u]
else:
log("get_formsemestre_inscription_cache: new simpleCache")
CACHE_formsemestre_inscription[u] = sco_cache.simpleCache()
return CACHE_formsemestre_inscription[u]