Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where serializing vocabulary terms into '|' syntax failed when values contained non-ascii characters #61

Merged
merged 4 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ New features:

Bug fixes:

- Fix issue where serializing vocabulary terms into '|' syntax failed when
values contained non-ascii characters
[datakurre]

- Allow defaults to be set on dexterity type fields via the web UI (@@fields)
[ezvirtual]

Expand Down
10 changes: 6 additions & 4 deletions plone/schemaeditor/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def __getattr__(self, name):
values = []
for term in (self.field.vocabulary or []):
if term.value != term.title:
values.append('{0:s}|{1:s}'.format(term.value, term.title))
values.append(u'{0:s}|{1:s}'.format(
term.value, term.title))
else:
values.append(term.value)
return values
Expand All @@ -132,8 +133,8 @@ def _constructVocabulary(self, value):
terms = []
if value:
for item in value:
if item and '|' in item:
voc_value, voc_title = item.split('|', 1)
if item and u'|' in item:
voc_value, voc_title = item.split(u'|', 1)
else:
voc_value = item
voc_title = item
Expand Down Expand Up @@ -260,7 +261,8 @@ def __getattr__(self, name):
values = []
for term in (self.field.value_type.vocabulary or []):
if term.value != term.title:
values.append('{0:s}|{1:s}'.format(term.value, term.title))
values.append(u'{0:s}|{1:s}'.format(
term.value, term.title))
else:
values.append(term.value)
return values
Expand Down
8 changes: 8 additions & 0 deletions plone/schemaeditor/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def assertVocabulary(self, voc, values):
def test_singlechoice_voc(self):
field = TextLineChoiceField(DummyField())
field.values = [u'New York', u'city2|München']
self.assertEqual(
field.values,
[u'New York', u'city2|München']
)
self.assertVocabulary(
field.vocabulary,
[(u'New York', u'New York', u'New York'),
Expand All @@ -39,6 +43,10 @@ def test_singlechoice_voc(self):
def test_multichoice_voc(self):
field = TextLineMultiChoiceField(DummyField())
field.values = [u'New York', u'city1|Zürich']
self.assertEqual(
field.values,
[u'New York', u'city1|Zürich']
)
self.assertVocabulary(
field.vocabulary,
[(u'New York', u'New York', u'New York'),
Expand Down