From 7b0716e513e001c5221d86f76f5e063d4dfb1b19 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 23 Jan 2020 14:33:38 +0100 Subject: [PATCH 09/11] create_formdata: fix XML export/import of mappings with py3 --- wcs/wf/create_formdata.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wcs/wf/create_formdata.py b/wcs/wf/create_formdata.py index d2a68080..f8a65b4d 100644 --- a/wcs/wf/create_formdata.py +++ b/wcs/wf/create_formdata.py @@ -22,6 +22,7 @@ import xml.etree.ElementTree as ET from quixote import get_request, get_session from django.utils.functional import cached_property +from django.utils.encoding import force_text, force_str from wcs.qommon import _ from wcs.qommon.form import (WidgetListAsTable, CompositeWidget, @@ -427,14 +428,14 @@ class CreateFormdataWorkflowStatusItem(WorkflowStatusItem): container = ET.SubElement(parent, 'mappings') for mapping in self.mappings or []: item = ET.SubElement(container, 'mapping') - item.attrib['varname'] = unicode(mapping.varname, charset, 'replace') - item.text = unicode(mapping.expression, charset, 'replace') + item.attrib['varname'] = force_text(mapping.varname, encoding=charset) + item.text = force_text(mapping.expression, encoding=charset) def mappings_init_with_xml(self, container, charset, include_id=False): self.mappings = [] for child in container: - varname = child.attrib.get('varname', '').encode(charset) - expression = child.text.encode(charset) + varname = force_str(child.attrib.get('varname', ''), encoding=charset) + expression = force_str(child.text, encoding=charset) if varname: self.mappings.append(Mapping(varname=varname, expression=expression)) -- 2.24.0