xml without jaxml

This commit is contained in:
Emmanuel Viennet 2021-07-10 17:22:27 +02:00
parent cdc1969520
commit ec8bef7984

View File

@ -39,9 +39,10 @@ import re
import sets import sets
import operator import operator
# XML generation package (apt-get install jaxml)
import jaxml
import xml.dom.minidom import xml.dom.minidom
from xml.etree import ElementTree
from xml.etree.ElementTree import Element
import app.scodoc.sco_utils as scu import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb import app.scodoc.notesdb as ndb
@ -52,9 +53,11 @@ from app.scodoc import sco_codes_parcours
from app.scodoc import sco_core from app.scodoc import sco_core
from app.scodoc import sco_etud from app.scodoc import sco_etud
from app.scodoc import sco_permissions_check from app.scodoc import sco_permissions_check
from app.scodoc import sco_xml
from app.scodoc.sco_exceptions import ScoException, AccessDenied, ScoValueError from app.scodoc.sco_exceptions import ScoException, AccessDenied, ScoValueError
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.scodoc.TrivialFormulator import TrivialFormulator from app.scodoc.TrivialFormulator import TrivialFormulator
import six import six
@ -427,13 +430,16 @@ def formsemestre_partition_list(context, formsemestre_id, format="xml", REQUEST=
return scu.sendResult(REQUEST, partitions, name="partition", format=format) return scu.sendResult(REQUEST, partitions, name="partition", format=format)
# Encore utilisé par groupmgr.js
def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetGroupesTD def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetGroupesTD
""" """
Deprecated: use group_list Deprecated: use group_list
Liste des étudiants dans chaque groupe de cette partition. Liste des étudiants dans chaque groupe de cette partition.
<group partition_id="" partition_name="" group_id="" group_name=""> <group partition_id="" partition_name="" group_id="" group_name="">
<etud etuid="" sexe="" nom="" prenom="" origin=""/> <etud etuid="" sexe="" nom="" prenom="" civilite="" origin=""/>
</groupe> </group>
<group ...>
...
""" """
from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre
@ -448,22 +454,23 @@ def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetG
etuds_set = set(nt.inscrdict) etuds_set = set(nt.inscrdict)
# XML response: # XML response:
REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE) REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE)
doc = jaxml.XML_document(encoding=scu.SCO_ENCODING) doc = Element("ajax-response")
doc._text('<ajax-response><response type="object" id="MyUpdater">') x_response = Element("response", type="object", id="MyUpdater")
doc._push() doc.append(x_response)
for group in groups: for group in groups:
doc._push() x_group = Element(
doc.group( "group",
partition_id=partition_id, partition_id=partition_id,
partition_name=partition["partition_name"], partition_name=partition["partition_name"],
group_id=group["group_id"], group_id=group["group_id"],
group_name=group["group_name"], group_name=group["group_name"],
) )
x_response.append(x_group)
for e in get_group_members(context, group["group_id"]): for e in get_group_members(context, group["group_id"]):
etud = sco_etud.get_etud_info(etudid=e["etudid"], filled=1)[0] etud = sco_etud.get_etud_info(etudid=e["etudid"], filled=1)[0]
doc._push() x_group.append(
doc.etud( Element(
"etud",
etudid=e["etudid"], etudid=e["etudid"],
civilite=etud["civilite_str"], civilite=etud["civilite_str"],
sexe=etud["civilite_str"], # compat sexe=etud["civilite_str"], # compat
@ -471,37 +478,34 @@ def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetG
prenom=sco_etud.format_prenom(etud["prenom"]), prenom=sco_etud.format_prenom(etud["prenom"]),
origin=comp_origin(etud, sem), origin=comp_origin(etud, sem),
) )
)
if e["etudid"] in etuds_set: if e["etudid"] in etuds_set:
etuds_set.remove(e["etudid"]) # etudiant vu dans un groupe etuds_set.remove(e["etudid"]) # etudiant vu dans un groupe
doc._pop()
doc._pop()
# Ajoute les etudiants inscrits au semestre mais dans aucun groupe de cette partition: # Ajoute les etudiants inscrits au semestre mais dans aucun groupe de cette partition:
if etuds_set: if etuds_set:
doc._push() x_group = Element(
doc.group( "group",
partition_id=partition_id, partition_id=partition_id,
partition_name=partition["partition_name"], partition_name=partition["partition_name"],
group_id="_none_", group_id="_none_",
group_name="", group_name="",
) )
doc.append(x_group)
for etudid in etuds_set: for etudid in etuds_set:
etud = sco_etud.get_etud_info(etudid=etudid, filled=1)[0] etud = sco_etud.get_etud_info(etudid=etudid, filled=1)[0]
doc._push() x_group.append(
doc.etud( Element(
"etud",
etudid=etud["etudid"], etudid=etud["etudid"],
sexe=etud["civilite_str"], sexe=etud["civilite_str"],
nom=sco_etud.format_nom(etud["nom"]), nom=sco_etud.format_nom(etud["nom"]),
prenom=sco_etud.format_prenom(etud["prenom"]), prenom=sco_etud.format_prenom(etud["prenom"]),
origin=comp_origin(etud, sem), origin=comp_origin(etud, sem),
) )
doc._pop() )
doc._pop()
doc._pop()
doc._text("</response></ajax-response>")
log("XMLgetGroupsInPartition: %s seconds" % (time.time() - t0)) log("XMLgetGroupsInPartition: %s seconds" % (time.time() - t0))
return repr(doc) return sco_xml.XML_HEADER + ElementTree.tostring(doc)
def comp_origin(etud, cur_sem): def comp_origin(etud, cur_sem):