From dca51d1ce4de32269f5be4466fb83cf7a8be2e1c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 30 Aug 2021 23:28:15 +0200 Subject: [PATCH] =?UTF-8?q?trois=20bugs=20=C3=A9pars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/__init__.py | 4 ++- app/scodoc/sco_edit_formation.py | 2 +- app/scodoc/sco_edit_ue.py | 29 +++++++++++++-------- app/scodoc/sco_evaluations.py | 1 + app/scodoc/sco_formsemestre_edit.py | 2 +- app/scodoc/sco_formsemestre_exterieurs.py | 7 ++--- app/scodoc/sco_formsemestre_inscriptions.py | 29 +++++++++++++-------- app/scodoc/sco_formsemestre_validation.py | 6 +++-- app/scodoc/sco_pvjury.py | 4 +-- app/scodoc/sco_utils.py | 2 +- 10 files changed, 53 insertions(+), 33 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index a883f89ab..e72f75d1c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -301,9 +301,11 @@ def clear_scodoc_cache(): # --------- Logging -def log(msg: str): +def log(msg: str, silent_test=True): """log a message. If Flask app, use configured logger, else stderr.""" + if silent_test and current_app.config["TESTING"]: + return try: dept = getattr(g, "scodoc_dept", "") msg = f" ({dept}) {msg}" diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 7c666d16d..b52c3a53e 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -348,7 +348,7 @@ def module_move(module_id, after=0, REQUEST=None, redirect=1): ) -def ue_move(ue_id, after=0, REQUEST=None, redirect=1): +def ue_move(ue_id, after=0, redirect=1): """Move UE before/after previous one (decrement/increment numero)""" o = sco_edit_ue.do_ue_list({"ue_id": ue_id})[0] # log('ue_move %s (#%s) after=%s' % (ue_id, o['numero'], after)) diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index e19e7e178..b717daea0 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -115,7 +115,7 @@ def do_ue_create(args): return r -def do_ue_delete(ue_id, delete_validations=False, REQUEST=None, force=False): +def do_ue_delete(ue_id, delete_validations=False, force=False): "delete UE and attached matieres (but not modules)" from app.scodoc import sco_formations from app.scodoc import sco_parcours_dut @@ -420,10 +420,10 @@ def ue_delete( cancel_url="ue_list?formation_id=%s" % ue["formation_id"], ) - return do_ue_delete(ue_id, delete_validations=delete_validations, REQUEST=REQUEST) + return do_ue_delete(ue_id, delete_validations=delete_validations) -def ue_list(formation_id=None, msg="", REQUEST=None): +def ue_list(formation_id=None, msg=""): """Liste des matières et modules d'une formation, avec liens pour editer (si non verrouillée). """ @@ -484,22 +484,29 @@ def ue_list(formation_id=None, msg="", REQUEST=None): ] if locked: H.append( - """

Cette formation est verrouillée car %d semestres verrouillés s'y réferent. -Si vous souhaitez modifier cette formation (par exemple pour y ajouter un module), vous devez: + f"""

Cette formation est verrouillée car +{len(locked)} semestres verrouillés s'y réferent. +Si vous souhaitez modifier cette formation (par exemple pour y ajouter un module), +vous devez:

""" - % len(locked) ) if msg: H.append('

' + msg + "

") if has_duplicate_ue_codes: H.append( - """
Attention: plusieurs UE de cette formation ont le même code. Il faut corriger cela ci-dessous, sinon les calculs d'ECTS seront erronés !
""" + """
Attention: plusieurs UE de cette + formation ont le même code. Il faut corriger cela ci-dessous, + sinon les calculs d'ECTS seront erronés !
""" ) # Description de la formation @@ -914,7 +921,7 @@ def do_ue_edit(args, bypass_lock=False, dont_invalidate_cache=False): # essai edition en ligne: -def edit_ue_set_code_apogee(id=None, value=None, REQUEST=None): +def edit_ue_set_code_apogee(id=None, value=None): "set UE code apogee" ue_id = id value = value.strip("-_ \t") diff --git a/app/scodoc/sco_evaluations.py b/app/scodoc/sco_evaluations.py index 45a555d89..b526e0831 100644 --- a/app/scodoc/sco_evaluations.py +++ b/app/scodoc/sco_evaluations.py @@ -39,6 +39,7 @@ from flask import g from flask_login import current_user from flask import request +from app import log import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app.scodoc.sco_exceptions import AccessDenied, ScoValueError diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index df2285616..9328a5f1c 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -195,7 +195,7 @@ def do_formsemestre_createwithmodules(REQUEST=None, edit=False): if sid == "-1": semestre_id_labels.append("pas de semestres") else: - semestre_id_labels.append(str(sid)) + semestre_id_labels.append(f"S{sid}") # Liste des modules dans ce semestre de cette formation # on pourrait faire un simple module_list( ) # mais si on veut l'ordre du PPN (groupe par UE et matieres) il faut: diff --git a/app/scodoc/sco_formsemestre_exterieurs.py b/app/scodoc/sco_formsemestre_exterieurs.py index ca3c4294e..59e890dff 100644 --- a/app/scodoc/sco_formsemestre_exterieurs.py +++ b/app/scodoc/sco_formsemestre_exterieurs.py @@ -128,7 +128,8 @@ def formsemestre_ext_create_form(etudid, formsemestre_id, REQUEST=None): H.append("""

pas de semestres extérieurs possibles

""") return "\n".join(H) + F # Formulaire - semestre_ids_str = [str(x) for x in sorted(semestre_ids)] + semestre_ids_list = sorted(semestre_ids) + semestre_ids_labels = [f"S{x}" for x in semestre_ids_list] descr = [ ("formsemestre_id", {"input_type": "hidden"}), ("etudid", {"input_type": "hidden"}), @@ -137,8 +138,8 @@ def formsemestre_ext_create_form(etudid, formsemestre_id, REQUEST=None): { "input_type": "menu", "title": "Indice du semestre dans le cursus", - "allowed_values": semestre_ids_str, - "labels": semestre_ids_str, + "allowed_values": semestre_ids_list, + "labels": semestre_ids_labels, }, ), ( diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index 627a2844d..99e4f26ed 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -478,9 +478,9 @@ def formsemestre_inscription_option(etudid, formsemestre_id, REQUEST=None): if ins["moduleimpl_id"] == mod["moduleimpl_id"]: key = "moduleimpls_%s" % ue_id if key in initvalues: - initvalues[key].append(mod["moduleimpl_id"]) + initvalues[key].append(str(mod["moduleimpl_id"])) else: - initvalues[key] = [mod["moduleimpl_id"]] + initvalues[key] = [str(mod["moduleimpl_id"])] break descr = [ @@ -506,7 +506,7 @@ def formsemestre_inscription_option(etudid, formsemestre_id, REQUEST=None): "sec_%s" % ue_id, { "input_type": "separator", - "title": """%s : inscrire|désinscrire à tous les modules""" + "title": """%s : inscrire | désinscrire à tous les modules""" % (ue_descr, ue_id, ue_id), }, ) @@ -518,7 +518,7 @@ def formsemestre_inscription_option(etudid, formsemestre_id, REQUEST=None): "input_type": "checkbox", "title": "", "dom_id": ue_id, - "allowed_values": modimpls_by_ue_ids[ue_id], + "allowed_values": [str(x) for x in modimpls_by_ue_ids[ue_id]], "labels": modimpls_by_ue_names[ue_id], "vertical": True, }, @@ -569,18 +569,21 @@ function chkbx_select(field_id, state) { insdict[ins["moduleimpl_id"]] = ins for ue in ues: ue_id = ue["ue_id"] - for moduleimpl_id in tf[2]["moduleimpls_%s" % ue_id]: + for moduleimpl_id in [int(x) for x in tf[2]["moduleimpls_%s" % ue_id]]: if moduleimpl_id in a_desinscrire: del a_desinscrire[moduleimpl_id] # supprime ceux auxquel pas inscrit - for moduleimpl_id in a_desinscrire.keys(): + moduleimpls_a_desinscrire = list(a_desinscrire.keys()) + for moduleimpl_id in moduleimpls_a_desinscrire: if moduleimpl_id not in insdict: del a_desinscrire[moduleimpl_id] a_inscrire = set() for ue in ues: ue_id = ue["ue_id"] - a_inscrire.update(tf[2]["moduleimpls_%s" % ue_id]) + a_inscrire.update( + int(x) for x in tf[2]["moduleimpls_%s" % ue_id] + ) # conversion en int ! # supprime ceux auquel deja inscrit: for ins in inscr: if ins["moduleimpl_id"] in a_inscrire: @@ -638,8 +641,8 @@ function chkbx_select(field_id, state) { + "

" ) H.append("") - modulesimpls_ainscrire = ",".join(a_inscrire) - modulesimpls_adesinscrire = ",".join(a_desinscrire) + modulesimpls_ainscrire = ",".join(str(x) for x in a_inscrire) + modulesimpls_adesinscrire = ",".join(str(x) for x in a_desinscrire) H.append( """
@@ -665,12 +668,16 @@ def do_moduleimpl_incription_options( """ Effectue l'inscription et la description aux modules optionnels """ + if isinstance(modulesimpls_ainscrire, int): + modulesimpls_ainscrire = str(modulesimpls_ainscrire) + if isinstance(modulesimpls_adesinscrire, int): + modulesimpls_adesinscrire = str(modulesimpls_adesinscrire) if modulesimpls_ainscrire: - a_inscrire = modulesimpls_ainscrire.split(",") + a_inscrire = [int(x) for x in modulesimpls_ainscrire.split(",")] else: a_inscrire = [] if modulesimpls_adesinscrire: - a_desinscrire = modulesimpls_adesinscrire.split(",") + a_desinscrire = [int(x) for x in modulesimpls_adesinscrire.split(",")] else: a_desinscrire = [] # inscriptions diff --git a/app/scodoc/sco_formsemestre_validation.py b/app/scodoc/sco_formsemestre_validation.py index 47ffd83f6..38fea2389 100644 --- a/app/scodoc/sco_formsemestre_validation.py +++ b/app/scodoc/sco_formsemestre_validation.py @@ -317,8 +317,10 @@ def formsemestre_validation_etud_form( H.append(form_decision_manuelle(Se, formsemestre_id, etudid)) H.append( - """""" - % (etudid, formsemestre_id) + f"""""" ) H.append('

Formation ') diff --git a/app/scodoc/sco_pvjury.py b/app/scodoc/sco_pvjury.py index c49c58449..3fa5196ae 100644 --- a/app/scodoc/sco_pvjury.py +++ b/app/scodoc/sco_pvjury.py @@ -320,13 +320,13 @@ def dict_pvjury( # Cherche la date de decision (sem ou UE) la plus récente: if d["decision_sem"]: date = ndb.DateDMYtoISO(d["decision_sem"]["event_date"]) - if date > max_date: # decision plus recente + if date and date > max_date: # decision plus recente max_date = date if d["decisions_ue"]: for dec_ue in d["decisions_ue"].values(): if dec_ue: date = ndb.DateDMYtoISO(dec_ue["event_date"]) - if date > max_date: # decision plus recente + if date and date > max_date: # decision plus recente max_date = date # Code semestre precedent if with_prev: # optionnel car un peu long... diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 58bf97568..9acb31293 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -56,7 +56,7 @@ from PIL import Image as PILImage from flask import g, url_for, request from config import Config - +from app import log from app.scodoc.sco_vdi import ApoEtapeVDI from app.scodoc.sco_xml import quote_xml_attr from app.scodoc.sco_codes_parcours import NOTES_TOLERANCE, CODES_EXPL