ScoDoc/app/scodoc/sco_core.py

90 lines
2.8 KiB
Python

# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""essai: ceci serait un module scodoc/sco_xxx.py
"""
import types
from flask import url_for
import sco_utils as scu
from notes_table import NOTES_CACHE_INST, CacheNotesTable
from scodoc_manager import sco_mgr
from sco_exceptions import ScoInvalidDept
def sco_get_version(context, REQUEST=None):
"""Une fonction typique de ScoDoc7"""
return """<html><body><p>%s</p></body></html>""" % scu.SCOVERSION
def test_refactor(context, x=1):
x = context.toto()
y = ("context=" + sco_edit_module.module_is_locked(context, "alpha")) + "23"
z = html_sco_header.sco_header(
context,
a_long_argument_hahahahaha=1,
another_very_long_arggggggggggggg=2,
z=6,
u=99,
kkkkkk=1,
)
#
# 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]