forked from ScoDoc/ScoDoc
Export Apo: cache inscrits étapes
This commit is contained in:
parent
9212f72581
commit
75f8c3b500
@ -37,12 +37,20 @@ import xml.dom.minidom
|
||||
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app import log
|
||||
from app.scodoc import sco_cache
|
||||
from app.scodoc.sco_exceptions import ScoValueError
|
||||
from app.scodoc import sco_preferences
|
||||
|
||||
SCO_CACHE_ETAPE_FILENAME = os.path.join(scu.SCO_TMP_DIR, "last_etapes.xml")
|
||||
|
||||
|
||||
class ApoInscritsEtapeCache(sco_cache.ScoDocCache):
|
||||
"""Cache liste des inscrits à une étape Apogée"""
|
||||
|
||||
timeout = 10 * 60 # 10 minutes
|
||||
prefix = "APOINSCRETAP"
|
||||
|
||||
|
||||
def has_portal():
|
||||
"True if we are connected to a portal"
|
||||
return get_portal_url()
|
||||
@ -139,14 +147,20 @@ get_maquette_url = _PI.get_maquette_url
|
||||
get_portal_api_version = _PI.get_portal_api_version
|
||||
|
||||
|
||||
def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2):
|
||||
def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2, use_cache=True):
|
||||
"""Liste des inscrits à une étape Apogée
|
||||
Result = list of dicts
|
||||
ntrials: try several time the same request, useful for some bad web services
|
||||
use_cache: use (redis) cache
|
||||
"""
|
||||
log("get_inscrits_etape: code=%s anneeapogee=%s" % (code_etape, anneeapogee))
|
||||
if anneeapogee is None:
|
||||
anneeapogee = str(time.localtime()[0])
|
||||
if use_cache:
|
||||
obj = ApoInscritsEtapeCache.get((code_etape, anneeapogee))
|
||||
if obj:
|
||||
log("get_inscrits_etape: using cached data")
|
||||
return obj
|
||||
|
||||
etud_url = get_etud_url()
|
||||
api_ver = get_portal_api_version()
|
||||
@ -189,6 +203,8 @@ def get_inscrits_etape(code_etape, anneeapogee=None, ntrials=2):
|
||||
return False # ??? pas d'annee d'inscription dans la réponse
|
||||
|
||||
etuds = [e for e in etuds if check_inscription(e)]
|
||||
if use_cache and etuds:
|
||||
ApoInscritsEtapeCache.set((code_etape, anneeapogee), etuds)
|
||||
return etuds
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
SCOVERSION = "9.2.8"
|
||||
SCOVERSION = "9.2.9"
|
||||
|
||||
SCONAME = "ScoDoc"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user