forked from ScoDoc/ScoDoc
Import Apo: tolère erreur si etudiant apo dupliqué
This commit is contained in:
parent
098502f2d3
commit
cc579c59f7
@ -35,6 +35,8 @@ import xml
|
|||||||
import xml.sax.saxutils
|
import xml.sax.saxutils
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
|
||||||
|
from flask import flash
|
||||||
|
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
from app import log
|
from app import log
|
||||||
from app.scodoc import sco_cache
|
from app.scodoc import sco_cache
|
||||||
@ -67,7 +69,7 @@ class PortalInterface(object):
|
|||||||
portal_url += "/"
|
portal_url += "/"
|
||||||
if self.first_time:
|
if self.first_time:
|
||||||
if portal_url:
|
if portal_url:
|
||||||
log("Portal URL=%s" % portal_url)
|
log(f"Portal URL={portal_url}")
|
||||||
else:
|
else:
|
||||||
log("Portal not configured")
|
log("Portal not configured")
|
||||||
self.first_time = False
|
self.first_time = False
|
||||||
@ -338,16 +340,18 @@ def get_etud_apogee(code_nip):
|
|||||||
if not d:
|
if not d:
|
||||||
return None
|
return None
|
||||||
if len(d) > 1:
|
if len(d) > 1:
|
||||||
raise ValueError("invalid XML response from Etudiant Web Service\n%s" % doc)
|
log(f"get_etud_apogee({code_nip}): {len(d)} etudiants !\n{doc}")
|
||||||
|
flash("Attention: plusieurs étudiants inscrits avec le NIP {code_nip}")
|
||||||
|
# dans ce cas, renvoie le premier étudiant
|
||||||
return d[0]
|
return d[0]
|
||||||
|
|
||||||
|
|
||||||
def get_default_etapes():
|
def get_default_etapes():
|
||||||
"""Liste par défaut, lue du fichier de config"""
|
"""Liste par défaut, lue du fichier de config"""
|
||||||
filename = scu.SCO_TOOLS_DIR + "/default-etapes.txt"
|
filename = scu.SCO_TOOLS_DIR + "/default-etapes.txt"
|
||||||
log("get_default_etapes: reading %s" % filename)
|
log(f"get_default_etapes: reading {filename}")
|
||||||
f = open(filename)
|
|
||||||
etapes = {}
|
etapes = {}
|
||||||
|
with open(filename, encoding=scu.SCO_ENCODING) as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and line[0] != "#":
|
if line and line[0] != "#":
|
||||||
@ -369,7 +373,7 @@ def _parse_etapes_from_xml(doc):
|
|||||||
dom = xml.dom.minidom.parseString(doc)
|
dom = xml.dom.minidom.parseString(doc)
|
||||||
infos = {}
|
infos = {}
|
||||||
if dom.childNodes[0].nodeName != "etapes":
|
if dom.childNodes[0].nodeName != "etapes":
|
||||||
raise ValueError
|
raise ValueError("élément 'etapes' attendu")
|
||||||
if xml_etapes_by_dept:
|
if xml_etapes_by_dept:
|
||||||
# Ancien format XML avec des sections par departement:
|
# Ancien format XML avec des sections par departement:
|
||||||
for d in dom.childNodes[0].childNodes:
|
for d in dom.childNodes[0].childNodes:
|
||||||
@ -394,8 +398,7 @@ def get_etapes_apogee():
|
|||||||
if etapes_url:
|
if etapes_url:
|
||||||
portal_timeout = sco_preferences.get_preference("portal_timeout")
|
portal_timeout = sco_preferences.get_preference("portal_timeout")
|
||||||
log(
|
log(
|
||||||
"get_etapes_apogee: requesting '%s' with timeout=%s"
|
f"""get_etapes_apogee: requesting '{etapes_url}' with timeout={portal_timeout}"""
|
||||||
% (etapes_url, portal_timeout)
|
|
||||||
)
|
)
|
||||||
doc = scu.query_portal(etapes_url, timeout=portal_timeout)
|
doc = scu.query_portal(etapes_url, timeout=portal_timeout)
|
||||||
try:
|
try:
|
||||||
@ -403,15 +406,17 @@ def get_etapes_apogee():
|
|||||||
# cache le resultat (utile si le portail repond de façon intermitente)
|
# cache le resultat (utile si le portail repond de façon intermitente)
|
||||||
if infos:
|
if infos:
|
||||||
log("get_etapes_apogee: caching result")
|
log("get_etapes_apogee: caching result")
|
||||||
with open(SCO_CACHE_ETAPE_FILENAME, "w") as f:
|
with open(
|
||||||
|
SCO_CACHE_ETAPE_FILENAME, "w", encoding=scu.SCO_ENCODING
|
||||||
|
) as f:
|
||||||
f.write(doc)
|
f.write(doc)
|
||||||
except:
|
except:
|
||||||
log("invalid XML response from getEtapes Web Service\n%s" % etapes_url)
|
log(f"invalid XML response from getEtapes Web Service\n{etapes_url}")
|
||||||
# Avons nous la copie d'une réponse récente ?
|
# Avons-nous la copie d'une réponse récente ?
|
||||||
try:
|
try:
|
||||||
doc = open(SCO_CACHE_ETAPE_FILENAME).read()
|
doc = open(SCO_CACHE_ETAPE_FILENAME, encoding=scu.SCO_ENCODING).read()
|
||||||
infos = _parse_etapes_from_xml(doc)
|
infos = _parse_etapes_from_xml(doc)
|
||||||
log("using last saved version from " + SCO_CACHE_ETAPE_FILENAME)
|
log(f"using last saved version from {SCO_CACHE_ETAPE_FILENAME}")
|
||||||
except:
|
except:
|
||||||
infos = {}
|
infos = {}
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user