Commit 4d77df80 authored by Nicolas Delaby's avatar Nicolas Delaby

* Support XML un/serialisation of forms which are contain ProxyFields,

by exporting delegated_list property.
* fix indentation issue which duplicates 'tales' node in formToXML
brought by r27696


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33654 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ca3390bd
...@@ -69,6 +69,13 @@ def formToXML(form, prologue=1): ...@@ -69,6 +69,13 @@ def formToXML(form, prologue=1):
for message_key in field.get_error_names(): for message_key in field.get_error_names():
message_element = SubElement(messages, 'message', name=message_key) message_element = SubElement(messages, 'message', name=message_key)
message_element.text = escape(field.get_error_message(message_key)).decode(encoding) message_element.text = escape(field.get_error_message(message_key)).decode(encoding)
# Special attribute for ProxyFields *delegated_list*
delegated_list = getattr(field, 'delegated_list', [])
if delegated_list:
delegated_list_element = SubElement(field_element, 'delegated_list')
delegated_list.sort()
[SubElement(delegated_list_element, delegated) for delegated in delegated_list]
form_as_string = etree.tostring(form_as_xml, encoding='utf-8', form_as_string = etree.tostring(form_as_xml, encoding='utf-8',
xml_declaration=True, pretty_print=True) xml_declaration=True, pretty_print=True)
if form.unicode_mode: if form.unicode_mode:
......
# -*- coding: utf-8 -*-
import XMLObjects import XMLObjects
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from Products.Formulator.MethodField import Method from Products.Formulator.MethodField import Method
...@@ -110,10 +111,19 @@ def XMLToForm(s, form, override_encoding=None): ...@@ -110,10 +111,19 @@ def XMLToForm(s, form, override_encoding=None):
text = encode(entry.text, encoding) text = encode(entry.text, encoding)
field.message_values[name] = text field.message_values[name] = text
# set delegated_list, mean ProxyField
is_proxy_field = False
if hasattr(entry.first, 'delegated_list'):
delegated_list_element = entry.first.delegated_list
delegated_list = delegated_list_element.getElementNames()
field.delegated_list = delegated_list
is_proxy_field = True
# for persistence machinery # for persistence machinery
field.values = field.values field.values = field.values
field.tales = field.tales field.tales = field.tales
field.message_values = field.message_values field.message_values = field.message_values
if is_proxy_field:
field.delegated_list = field.delegated_list
# delete default group # delete default group
if not has_default: if not has_default:
......
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