1
0
forked from ScoDoc/ScoDoc

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 operator
# XML generation package (apt-get install jaxml)
import jaxml
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.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_etud
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_permissions import Permission
from app.scodoc.TrivialFormulator import TrivialFormulator
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)
# Encore utilisé par groupmgr.js
def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetGroupesTD
"""
Deprecated: use group_list
Liste des étudiants dans chaque groupe de cette partition.
<group partition_id="" partition_name="" group_id="" group_name="">
<etud etuid="" sexe="" nom="" prenom="" origin=""/>
</groupe>
<etud etuid="" sexe="" nom="" prenom="" civilite="" origin=""/>
</group>
<group ...>
...
"""
from app.scodoc import sco_formsemestre
@ -448,60 +454,58 @@ def XMLgetGroupsInPartition(context, partition_id, REQUEST=None): # was XMLgetG
etuds_set = set(nt.inscrdict)
# XML response:
REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE)
doc = jaxml.XML_document(encoding=scu.SCO_ENCODING)
doc._text('<ajax-response><response type="object" id="MyUpdater">')
doc._push()
doc = Element("ajax-response")
x_response = Element("response", type="object", id="MyUpdater")
doc.append(x_response)
for group in groups:
doc._push()
doc.group(
x_group = Element(
"group",
partition_id=partition_id,
partition_name=partition["partition_name"],
group_id=group["group_id"],
group_name=group["group_name"],
)
x_response.append(x_group)
for e in get_group_members(context, group["group_id"]):
etud = sco_etud.get_etud_info(etudid=e["etudid"], filled=1)[0]
doc._push()
doc.etud(
etudid=e["etudid"],
civilite=etud["civilite_str"],
sexe=etud["civilite_str"], # compat
nom=sco_etud.format_nom(etud["nom"]),
prenom=sco_etud.format_prenom(etud["prenom"]),
origin=comp_origin(etud, sem),
x_group.append(
Element(
"etud",
etudid=e["etudid"],
civilite=etud["civilite_str"],
sexe=etud["civilite_str"], # compat
nom=sco_etud.format_nom(etud["nom"]),
prenom=sco_etud.format_prenom(etud["prenom"]),
origin=comp_origin(etud, sem),
)
)
if e["etudid"] in etuds_set:
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:
if etuds_set:
doc._push()
doc.group(
x_group = Element(
"group",
partition_id=partition_id,
partition_name=partition["partition_name"],
group_id="_none_",
group_name="",
)
doc.append(x_group)
for etudid in etuds_set:
etud = sco_etud.get_etud_info(etudid=etudid, filled=1)[0]
doc._push()
doc.etud(
etudid=etud["etudid"],
sexe=etud["civilite_str"],
nom=sco_etud.format_nom(etud["nom"]),
prenom=sco_etud.format_prenom(etud["prenom"]),
origin=comp_origin(etud, sem),
x_group.append(
Element(
"etud",
etudid=etud["etudid"],
sexe=etud["civilite_str"],
nom=sco_etud.format_nom(etud["nom"]),
prenom=sco_etud.format_prenom(etud["prenom"]),
origin=comp_origin(etud, sem),
)
)
doc._pop()
doc._pop()
doc._pop()
doc._text("</response></ajax-response>")
log("XMLgetGroupsInPartition: %s seconds" % (time.time() - t0))
return repr(doc)
return sco_xml.XML_HEADER + ElementTree.tostring(doc)
def comp_origin(etud, cur_sem):