Commit 28048ede authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fixup! * Fix escaping chars in FormGroup title * Use lxml to produce XML...

fixup!  * Fix escaping chars in FormGroup title  * Use lxml to produce XML view  * Update XMLToForm to follow escaping changes

some elements were double escaped.
parent bb7d1071
# -*- coding: utf-8 -*-
import six
from cgi import escape
from lxml import etree
from lxml.etree import Element, SubElement, CDATA
from lxml.etree import Element, SubElement
from lxml.builder import E
def formToXML(form, prologue=1):
......@@ -21,7 +20,7 @@ def formToXML(form, prologue=1):
else:
value = 'false'
sub_element = SubElement(form_as_xml, id)
sub_element.text = escape(str(value)).decode(encoding)
sub_element.text = str(value).decode(encoding)
groups = SubElement(form_as_xml, 'groups')
# export form groups
for group in form.get_groups(include_empty=1):
......@@ -58,7 +57,7 @@ def formToXML(form, prologue=1):
if not isinstance(value, six.string_types):
value = str(value)
value_element = SubElement(values_element, key)
value_element.text = escape(str(value)).decode(encoding)
value_element.text = str(value).decode(encoding)
tales_element = SubElement(field_element, 'tales')
items = field.tales.items()
......@@ -66,11 +65,11 @@ def formToXML(form, prologue=1):
for key, value in items:
if value:
tale_element = SubElement(tales_element, key)
tale_element.text = escape(str(value._text)).decode(encoding)
tale_element.text = str(value._text).decode(encoding)
messages = SubElement(field_element, 'messages')
for message_key in field.get_error_names():
message_element = SubElement(messages, 'message', name=message_key)
message_element.text = escape(field.get_error_message(message_key)).decode(encoding)
message_element.text = field.get_error_message(message_key).decode(encoding)
# Special attribute for ProxyFields *delegated_list*
delegated_list = getattr(field, 'delegated_list', [])
if delegated_list:
......@@ -78,8 +77,6 @@ def formToXML(form, prologue=1):
delegated_list.sort()
[SubElement(delegated_list_element, delegated) for delegated in delegated_list]
form_as_string = etree.tostring(form_as_xml, encoding='utf-8',
xml_declaration=True, pretty_print=True)
if form.unicode_mode:
return etree.tostring(form_as_xml, encoding='utf-8',
xml_declaration=True, pretty_print=True)
......
# -*- coding: utf-8 -*-
from xml.dom.minidom import parse, parseString, Node
from xml.sax.saxutils import unescape
# an extremely simple system for loading in XML into objects
class Object:
......@@ -41,7 +40,7 @@ def attributeToObject(parent, node):
def textToObject(parent, node):
# add this text to parents text content
parent.text += unescape(node.data)
parent.text += node.data
def processingInstructionToObject(parent, node):
# don't do anything with these
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment