From 76b533729f8f56e116687f87f87594984947e27c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 12 Jul 2021 23:34:18 +0200 Subject: [PATCH] misc fixes --- app/scodoc/gen_tables.py | 2 +- app/scodoc/sco_bulletins_xml.py | 2 +- app/scodoc/sco_groups.py | 2 +- app/scodoc/sco_liste_notes.py | 2 +- app/scodoc/sco_recapcomplet.py | 6 +++++- app/scodoc/sco_utils.py | 4 ++-- app/scodoc/sco_xml.py | 7 +++++-- app/views/absences.py | 2 +- app/views/notes.py | 8 ++++++-- app/views/users.py | 4 ++-- 10 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/scodoc/gen_tables.py b/app/scodoc/gen_tables.py index 85da8e685..470142ef9 100644 --- a/app/scodoc/gen_tables.py +++ b/app/scodoc/gen_tables.py @@ -585,7 +585,7 @@ class GenTable(object): v = "" x_cell = ElementTree.Element(cid, value=str(v)) x_row.append(x_cell) - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) def json(self): """JSON representation of the table.""" diff --git a/app/scodoc/sco_bulletins_xml.py b/app/scodoc/sco_bulletins_xml.py index 6cb548c38..42b871117 100644 --- a/app/scodoc/sco_bulletins_xml.py +++ b/app/scodoc/sco_bulletins_xml.py @@ -437,4 +437,4 @@ def make_xml_formsemestre_bulletinetud( if is_appending: return None else: - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index cdef47ace..b643117cf 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -503,7 +503,7 @@ def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetG ) ) log("XMLgetGroupsInPartition: %s seconds" % (time.time() - t0)) - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) def comp_origin(etud, cur_sem): diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index 08e535fb4..7346b838f 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -671,7 +671,7 @@ def _add_moymod_column( ) # note sur 20, ou 'NA','NI' row[col_id] = scu.fmt_note(val, keep_numeric=keep_numeric) row["_" + col_id + "_td_attrs"] = ' class="moyenne" ' - if isinstance(val, str): + if not isinstance(val, str): notes.append(val) nb_notes = nb_notes + 1 sum_notes += val diff --git a/app/scodoc/sco_recapcomplet.py b/app/scodoc/sco_recapcomplet.py index 46b939159..6c5282072 100644 --- a/app/scodoc/sco_recapcomplet.py +++ b/app/scodoc/sco_recapcomplet.py @@ -905,7 +905,11 @@ def _formsemestre_recapcomplet_xml( xml_nodate=xml_nodate, xml_with_decisions=xml_with_decisions, ) - return sco_xml.XML_HEADER + ElementTree.tostring(doc), "", "xml" + return ( + sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING), + "", + "xml", + ) def _formsemestre_recapcomplet_json( diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index c78f2084c..76ef86e9b 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -562,7 +562,7 @@ def sendXML(REQUEST, data, tagname=None, force_outer_xml_tag=True): if REQUEST: REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE) - return repr(doc) + return doc def sendResult(REQUEST, data, name=None, format=None, force_outer_xml_tag=True): @@ -823,7 +823,7 @@ def _sco_error_response(context, msg, format="html", REQUEST=None): elif format == "xml": REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE) doc = ElementTree.Element("error", msg=msg) - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) elif format == "json": REQUEST.RESPONSE.setHeader("content-type", JSON_MIMETYPE) return "undefined" # XXX voir quoi faire en cas d'erreur json diff --git a/app/scodoc/sco_xml.py b/app/scodoc/sco_xml.py index 403c468ea..f5a08a55b 100644 --- a/app/scodoc/sco_xml.py +++ b/app/scodoc/sco_xml.py @@ -32,9 +32,10 @@ from xml.etree import ElementTree import xml.sax.saxutils +from app.scodoc import sco_utils as scu from app.scodoc.sco_vdi import ApoEtapeVDI -XML_HEADER = """\n""" +XML_HEADER = """""" def quote_xml_attr(data): @@ -63,7 +64,9 @@ def simple_dictlist2xml(dictlist, doc=None, tagname=None, quote=False): if not tagname: raise ValueError("invalid empty tagname !") elements = _dictlist2xml(dictlist, root=[], tagname=tagname, quote=quote) - return XML_HEADER + "\n".join([ElementTree.tostring(x) for x in elements]) + return XML_HEADER + b"\n".join([ElementTree.tostring(x) for x in elements]).decode( + scu.SCO_ENCODING + ) def _dictlist2xml(dictlist, root=None, tagname=None, quote=False): diff --git a/app/views/absences.py b/app/views/absences.py index 977f75b71..c7f280a20 100644 --- a/app/views/absences.py +++ b/app/views/absences.py @@ -1534,7 +1534,7 @@ def XMLgetAbsEtud(context, beg_date="", end_date="", REQUEST=None): ) ) log("XMLgetAbsEtud (%gs)" % (time.time() - t0)) - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) context.populate(globals()) diff --git a/app/views/notes.py b/app/views/notes.py index 6a8289e4f..3fc7bd5b2 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -239,11 +239,13 @@ sco_publish( "/formsemestre_clone", sco_formsemestre_edit.formsemestre_clone, Permission.ScoImplement, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_associate_new_version", sco_formsemestre_edit.formsemestre_associate_new_version, Permission.ScoChangeFormation, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_delete", @@ -655,7 +657,7 @@ def XMLgetFormsemestres(context, etape_apo=None, formsemestre_id=None, REQUEST=N for sem in sco_formsemestre.do_formsemestre_list(context, args=args): doc.append("formsemestre", **sem) - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) sco_publish( @@ -673,6 +675,7 @@ sco_publish( "/formsemestre_change_lock", sco_formsemestre_edit.formsemestre_change_lock, Permission.ScoView, + methods=["GET", "POST"], ) sco_publish( "/formsemestre_change_publication_bul", @@ -721,7 +724,7 @@ def edit_enseignants_form(context, REQUEST, moduleimpl_id): userlist = sco_users.get_user_list() login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)" for u in userlist: - login2display[u["user_name"]] = u["nomplogin"] + login2display[u.user_name] = u.get_nomplogin() allowed_user_names = list(login2display.values()) H = [ @@ -1446,6 +1449,7 @@ sco_publish( "/moduleimpl_inscriptions_edit", sco_moduleimpl_inscriptions.moduleimpl_inscriptions_edit, Permission.ScoEtudInscrit, + methods=["GET", "POST"], ) sco_publish( "/moduleimpl_inscriptions_stats", diff --git a/app/views/users.py b/app/views/users.py index 58888eb51..d229d597d 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -473,10 +473,10 @@ def get_user_list_xml(dept=None, start="", limit=25, REQUEST=None): REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE) doc = ElementTree.Element("results") for user in userlist[:limit]: - x_rs = ElementTree.Element("rs", id=user.id, info="") + x_rs = ElementTree.Element("rs", id=str(user.id), info="") x_rs.text = user.get_nomplogin() doc.append(x_rs) - return sco_xml.XML_HEADER + ElementTree.tostring(doc) + return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING) @bp.route("/form_change_password")