1
0
forked from ScoDoc/ScoDoc

misc fixes

This commit is contained in:
Emmanuel Viennet 2021-07-13 09:38:31 +02:00
parent 76b533729f
commit ce36edd86d
5 changed files with 39 additions and 33 deletions

View File

@ -113,6 +113,11 @@ Pour créer un utilisateur "super admin", c'est à dire admin dans tous les dép
python -m unittest tests.test_users python -m unittest tests.test_users
# TODO
- page d'erreur ScoValueError
- redirection pour authentification
- import/export Excel

View File

@ -42,6 +42,7 @@ from app.scodoc import sco_formsemestre
from app.scodoc import sco_news from app.scodoc import sco_news
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
from app.scodoc import sco_tag_module from app.scodoc import sco_tag_module
from app.scodoc import sco_xml
from app.scodoc import VERSION from app.scodoc import VERSION
from app.scodoc.gen_tables import GenTable from app.scodoc.gen_tables import GenTable
from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_exceptions import ScoValueError
@ -133,35 +134,7 @@ def formation_export(
) )
ELEMENT_NODE = 1 def formation_import_xml(context, REQUEST, doc, import_tags=True):
TEXT_NODE = 3
def XMLToDicts(element, encoding):
"""Represent dom element as a dict
Example:
<foo x="1" y="2"><bar z="2"/></foo>
will give us:
('foo', {'y': '2', 'x': '1'}, [('bar', {'z': '2'}, [])])
"""
d = {}
# attributes
if element.attributes:
for i in range(len(element.attributes)):
a = element.attributes.item(i).nodeName.encode(encoding)
v = element.getAttribute(element.attributes.item(i).nodeName)
d[a] = v.encode(encoding)
# descendants
childs = []
for child in element.childNodes:
if child.nodeType == ELEMENT_NODE:
childs.append(XMLToDicts(child, encoding))
return (element.nodeName.encode(encoding), d, childs)
def formation_import_xml(
context, REQUEST, doc, import_tags=True, encoding=scu.SCO_ENCODING
):
"""Create a formation from XML representation """Create a formation from XML representation
(format dumped by formation_export( format='xml' )) (format dumped by formation_export( format='xml' ))
""" """
@ -175,7 +148,7 @@ def formation_import_xml(
raise ScoValueError("Fichier XML invalide") raise ScoValueError("Fichier XML invalide")
f = dom.getElementsByTagName("formation")[0] # or dom.documentElement f = dom.getElementsByTagName("formation")[0] # or dom.documentElement
D = XMLToDicts(f, encoding) D = sco_xml.xml_to_dicts(f)
assert D[0] == "formation" assert D[0] == "formation"
F = D[1] F = D[1]
F_quoted = F.copy() F_quoted = F.copy()

View File

@ -462,7 +462,7 @@ def build_page(
def formsemestre_inscr_passage_help(sem): def formsemestre_inscr_passage_help(sem):
return ( return (
"""<div class="pas_help pas_help_left"><h3><a name="help">Explications</a></h3> """<div class="pas_help"><h3><a name="help">Explications</a></h3>
<p>Cette page permet d'inscrire des étudiants dans le semestre destination <p>Cette page permet d'inscrire des étudiants dans le semestre destination
<a class="stdlink" <a class="stdlink"
href="formsemestre_status?formsemestre_id=%(formsemestre_id)s">%(titreannee)s</a>, href="formsemestre_status?formsemestre_id=%(formsemestre_id)s">%(titreannee)s</a>,

View File

@ -96,3 +96,29 @@ def _dictlist2xml(dictlist, root=None, tagname=None, quote=False):
for (k, v) in d_list.items(): for (k, v) in d_list.items():
_dictlist2xml(v, tagname=k, root=elem, quote=quote) _dictlist2xml(v, tagname=k, root=elem, quote=quote)
return root return root
ELEMENT_NODE = 1
TEXT_NODE = 3
def xml_to_dicts(element):
"""Represent dom element as a dict
Example:
<foo x="1" y="2"><bar z="2"/></foo>
will give us:
('foo', {'y': '2', 'x': '1'}, [('bar', {'z': '2'}, [])])
"""
d = {}
# attributes
if element.attributes:
for i in range(len(element.attributes)):
a = element.attributes.item(i).nodeName
v = element.getAttribute(element.attributes.item(i).nodeName)
d[a] = v
# descendants
childs = []
for child in element.childNodes:
if child.nodeType == ELEMENT_NODE:
childs.append(xml_to_dicts(child))
return (element.nodeName, d, childs)

View File

@ -251,11 +251,13 @@ sco_publish(
"/formsemestre_delete", "/formsemestre_delete",
sco_formsemestre_edit.formsemestre_delete, sco_formsemestre_edit.formsemestre_delete,
Permission.ScoImplement, Permission.ScoImplement,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/formsemestre_delete2", "/formsemestre_delete2",
sco_formsemestre_edit.formsemestre_delete2, sco_formsemestre_edit.formsemestre_delete2,
Permission.ScoImplement, Permission.ScoImplement,
methods=["GET", "POST"],
) )
sco_publish( sco_publish(
"/formsemestre_recapcomplet", "/formsemestre_recapcomplet",
@ -2170,7 +2172,7 @@ def formsemestre_fix_validation_ues(context, formsemestre_id, REQUEST=None):
) )
@bp.route("/formsemestre_validation_suppress_etud") @bp.route("/formsemestre_validation_suppress_etud", methods=["GET", "POST"])
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
@scodoc7func(context) @scodoc7func(context)
def formsemestre_validation_suppress_etud( def formsemestre_validation_suppress_etud(