Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
erp5
Commits
22d3da6e
Commit
22d3da6e
authored
Oct 25, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Plain Diff
Formulator: repair FormToXML for py2
See merge request
nexedi/erp5!2003
parents
e627161e
6316d9bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
16 deletions
+42
-16
product/Formulator/FormToXML.py
product/Formulator/FormToXML.py
+7
-16
product/Formulator/tests/testSerializeForm.py
product/Formulator/tests/testSerializeForm.py
+35
-0
No files found.
product/Formulator/FormToXML.py
View file @
22d3da6e
...
...
@@ -21,14 +21,12 @@ def formToXML(form, prologue=1):
else
:
value
=
'false'
sub_element
=
SubElement
(
form_as_xml
,
id
)
sub_element
.
text
=
str
(
value
)
if
six
.
PY2
:
sub_element
.
text
=
str2unicode
(
sub_element
.
text
,
encoding
)
sub_element
.
text
=
str2unicode
(
str
(
value
),
encoding
)
groups
=
SubElement
(
form_as_xml
,
'groups'
)
# export form groups
for
group
in
form
.
get_groups
(
include_empty
=
1
):
group_element
=
SubElement
(
groups
,
'group'
)
group_element
.
append
(
E
.
title
(
group
))
group_element
.
append
(
E
.
title
(
str2unicode
(
group
,
encoding
)
))
fields
=
SubElement
(
group_element
,
'fields'
)
for
field
in
form
.
get_fields_in_group
(
group
,
include_disabled
=
1
):
...
...
@@ -59,24 +57,19 @@ def formToXML(form, prologue=1):
if
not
isinstance
(
value
,
six
.
string_types
):
value
=
str
(
value
)
value_element
=
SubElement
(
values_element
,
key
)
value_element
.
text
=
str
(
value
)
if
six
.
PY2
:
value_element
.
text
=
str2unicode
(
value_element
.
text
,
encoding
)
value_element
.
text
=
str2unicode
(
str
(
value
),
encoding
)
tales_element
=
SubElement
(
field_element
,
'tales'
)
items
=
sorted
(
field
.
tales
.
items
())
for
key
,
value
in
items
:
if
value
:
tale_element
=
SubElement
(
tales_element
,
key
)
tale_element
.
text
=
str
(
value
.
_text
)
if
six
.
PY2
:
tale_element
.
text
=
str2unicode
(
tale_element
.
text
,
encoding
)
tale_element
.
text
=
str2unicode
(
str
(
value
.
_text
),
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
=
field
.
get_error_message
(
message_key
)
if
six
.
PY2
:
message_element
.
text
=
str2unicode
(
message_element
.
text
,
encoding
)
message_element
.
text
=
str2unicode
(
field
.
get_error_message
(
message_key
),
encoding
)
# Special attribute for ProxyFields *delegated_list*
delegated_list
=
getattr
(
field
,
'delegated_list'
,
[])
if
delegated_list
:
...
...
@@ -90,6 +83,4 @@ def formToXML(form, prologue=1):
else
:
xml
=
etree
.
tostring
(
form_as_xml
,
encoding
=
form
.
stored_encoding
,
xml_declaration
=
True
,
pretty_print
=
True
)
if
six
.
PY3
:
xml
=
bytes2str
(
xml
)
return
xml
return
bytes2str
(
xml
)
product/Formulator/tests/testSerializeForm.py
View file @
22d3da6e
...
...
@@ -189,6 +189,41 @@ class SerializeTestCase(unittest.TestCase):
# if we have forgotten something, this will usually remind us ;-)
self
.
assertEqual
(
form
.
render
(),
form2
.
render
())
def
test_encoding
(
self
):
"""test a form with non ascii string
"""
form
=
ZMIForm
(
'test'
,
'<EncodingTest>'
)
form
.
name
=
'name'
form
.
add_group
(
'àbcdé'
)
form
.
manage_addField
(
'string_field'
,
'string Field héhé'
,
'StringField'
)
form
.
manage_addField
(
'int_field'
,
'int Field héhé'
,
'IntegerField'
)
form
.
manage_addField
(
'float_field'
,
'Float Field héhé'
,
'FloatField'
)
form
.
manage_addField
(
'date_field'
,
'Date Field héhé'
,
'DateTimeField'
)
form
.
manage_addField
(
'list_field'
,
'List Field héhé'
,
'ListField'
)
form
.
manage_addField
(
'multi_field'
,
'Checkbox Field héhé'
,
'MultiCheckBoxField'
)
form2
=
ZMIForm
(
'test2'
,
'ValueTest'
)
xml
=
formToXML
(
form
)
XMLToForm
(
xml
,
form2
)
for
field
in
form
.
get_fields
():
self
.
assertTrue
(
form2
.
has_field
(
field
.
getId
()))
field2
=
getattr
(
form2
,
field
.
getId
())
self
.
assertEqual
(
field
.
values
,
field2
.
values
)
# test if default renderings are the same
self
.
assertEqual
(
field
.
render
(),
field2
.
render
())
self
.
assertEqual
(
form
.
title
,
form2
.
title
)
self
.
assertEqual
(
form
.
name
,
form2
.
name
)
self
.
assertEqual
(
form
.
action
,
form2
.
action
)
self
.
assertEqual
(
form
.
enctype
,
form2
.
enctype
)
self
.
assertEqual
(
form
.
method
,
form2
.
method
)
# if we have forgotten something, this will usually remind us ;-)
self
.
assertEqual
(
form
.
render
(),
form2
.
render
())
def
test_messages
(
self
):
""" test if the error messages are exported
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment