misc fixes

This commit is contained in:
Emmanuel Viennet 2021-07-12 23:34:18 +02:00
parent 1af9fb2410
commit 76b533729f
10 changed files with 25 additions and 14 deletions

View File

@ -585,7 +585,7 @@ class GenTable(object):
v = "" v = ""
x_cell = ElementTree.Element(cid, value=str(v)) x_cell = ElementTree.Element(cid, value=str(v))
x_row.append(x_cell) 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): def json(self):
"""JSON representation of the table.""" """JSON representation of the table."""

View File

@ -437,4 +437,4 @@ def make_xml_formsemestre_bulletinetud(
if is_appending: if is_appending:
return None return None
else: else:
return sco_xml.XML_HEADER + ElementTree.tostring(doc) return sco_xml.XML_HEADER + ElementTree.tostring(doc).decode(scu.SCO_ENCODING)

View File

@ -503,7 +503,7 @@ def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetG
) )
) )
log("XMLgetGroupsInPartition: %s seconds" % (time.time() - t0)) 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): def comp_origin(etud, cur_sem):

View File

@ -671,7 +671,7 @@ def _add_moymod_column(
) # note sur 20, ou 'NA','NI' ) # note sur 20, ou 'NA','NI'
row[col_id] = scu.fmt_note(val, keep_numeric=keep_numeric) row[col_id] = scu.fmt_note(val, keep_numeric=keep_numeric)
row["_" + col_id + "_td_attrs"] = ' class="moyenne" ' row["_" + col_id + "_td_attrs"] = ' class="moyenne" '
if isinstance(val, str): if not isinstance(val, str):
notes.append(val) notes.append(val)
nb_notes = nb_notes + 1 nb_notes = nb_notes + 1
sum_notes += val sum_notes += val

View File

@ -905,7 +905,11 @@ def _formsemestre_recapcomplet_xml(
xml_nodate=xml_nodate, xml_nodate=xml_nodate,
xml_with_decisions=xml_with_decisions, 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( def _formsemestre_recapcomplet_json(

View File

@ -562,7 +562,7 @@ def sendXML(REQUEST, data, tagname=None, force_outer_xml_tag=True):
if REQUEST: if REQUEST:
REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE) 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): 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": elif format == "xml":
REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE) REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE)
doc = ElementTree.Element("error", msg=msg) 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": elif format == "json":
REQUEST.RESPONSE.setHeader("content-type", JSON_MIMETYPE) REQUEST.RESPONSE.setHeader("content-type", JSON_MIMETYPE)
return "undefined" # XXX voir quoi faire en cas d'erreur json return "undefined" # XXX voir quoi faire en cas d'erreur json

View File

@ -32,9 +32,10 @@
from xml.etree import ElementTree from xml.etree import ElementTree
import xml.sax.saxutils import xml.sax.saxutils
from app.scodoc import sco_utils as scu
from app.scodoc.sco_vdi import ApoEtapeVDI from app.scodoc.sco_vdi import ApoEtapeVDI
XML_HEADER = """<?xml version="1.0" encoding="utf-8"?>\n""" XML_HEADER = """<?xml version="1.0" encoding="utf-8"?>"""
def quote_xml_attr(data): def quote_xml_attr(data):
@ -63,7 +64,9 @@ def simple_dictlist2xml(dictlist, doc=None, tagname=None, quote=False):
if not tagname: if not tagname:
raise ValueError("invalid empty tagname !") raise ValueError("invalid empty tagname !")
elements = _dictlist2xml(dictlist, root=[], tagname=tagname, quote=quote) 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): def _dictlist2xml(dictlist, root=None, tagname=None, quote=False):

View File

@ -1534,7 +1534,7 @@ def XMLgetAbsEtud(context, beg_date="", end_date="", REQUEST=None):
) )
) )
log("XMLgetAbsEtud (%gs)" % (time.time() - t0)) 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()) context.populate(globals())

View File

@ -239,11 +239,13 @@ sco_publish(
"/formsemestre_clone", "/formsemestre_clone",
sco_formsemestre_edit.formsemestre_clone, sco_formsemestre_edit.formsemestre_clone,
Permission.ScoImplement, Permission.ScoImplement,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/formsemestre_associate_new_version", "/formsemestre_associate_new_version",
sco_formsemestre_edit.formsemestre_associate_new_version, sco_formsemestre_edit.formsemestre_associate_new_version,
Permission.ScoChangeFormation, Permission.ScoChangeFormation,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/formsemestre_delete", "/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): for sem in sco_formsemestre.do_formsemestre_list(context, args=args):
doc.append("formsemestre", **sem) 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( sco_publish(
@ -673,6 +675,7 @@ sco_publish(
"/formsemestre_change_lock", "/formsemestre_change_lock",
sco_formsemestre_edit.formsemestre_change_lock, sco_formsemestre_edit.formsemestre_change_lock,
Permission.ScoView, Permission.ScoView,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/formsemestre_change_publication_bul", "/formsemestre_change_publication_bul",
@ -721,7 +724,7 @@ def edit_enseignants_form(context, REQUEST, moduleimpl_id):
userlist = sco_users.get_user_list() userlist = sco_users.get_user_list()
login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)" login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)"
for u in userlist: for u in userlist:
login2display[u["user_name"]] = u["nomplogin"] login2display[u.user_name] = u.get_nomplogin()
allowed_user_names = list(login2display.values()) allowed_user_names = list(login2display.values())
H = [ H = [
@ -1446,6 +1449,7 @@ sco_publish(
"/moduleimpl_inscriptions_edit", "/moduleimpl_inscriptions_edit",
sco_moduleimpl_inscriptions.moduleimpl_inscriptions_edit, sco_moduleimpl_inscriptions.moduleimpl_inscriptions_edit,
Permission.ScoEtudInscrit, Permission.ScoEtudInscrit,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/moduleimpl_inscriptions_stats", "/moduleimpl_inscriptions_stats",

View File

@ -473,10 +473,10 @@ def get_user_list_xml(dept=None, start="", limit=25, REQUEST=None):
REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE) REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE)
doc = ElementTree.Element("results") doc = ElementTree.Element("results")
for user in userlist[:limit]: 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() x_rs.text = user.get_nomplogin()
doc.append(x_rs) 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") @bp.route("/form_change_password")