misc: sort dictionary keys when exporting to xml (#36515)

This commit is contained in:
Frédéric Péters 2019-11-17 09:27:26 +01:00
parent 82fd9489bf
commit 478ff982a1
3 changed files with 3 additions and 3 deletions

View File

@ -240,7 +240,7 @@ class Field(object):
continue
el = ET.SubElement(field, attribute)
if type(val) is dict:
for k, v in val.items():
for k, v in sorted(val.items()):
if isinstance(v, str):
text_value = force_text(v, charset, errors='replace')
else:

View File

@ -959,7 +959,7 @@ class FormDef(StorableObject):
sub.text = role
options = ET.SubElement(root, 'options')
for option in self.workflow_options or []:
for option in sorted(self.workflow_options or []):
element = ET.SubElement(options, 'option')
element.attrib['varname'] = option
option_value = self.workflow_options.get(option)

View File

@ -528,7 +528,7 @@ class Workflow(StorableObject):
roles_node = ET.SubElement(root, 'roles')
if self.roles:
for role_id, role_label in self.roles.items():
for role_id, role_label in sorted(self.roles.items()):
role_node = ET.SubElement(roles_node, 'role')
role_node.attrib['id'] = role_id
role_node.text = force_text(role_label, charset)