Skip to content

Commit

Permalink
Merge pull request #61 from plone/datakurre-vocabularies
Browse files Browse the repository at this point in the history
 Fix issue where serializing vocabulary terms into '|' syntax failed when values contained non-ascii characters
  • Loading branch information
jensens authored Aug 14, 2018
2 parents 0bd2d1e + 234e017 commit f50e596
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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

1 comment on commit f50e596

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jensens Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.schemaeditor/45/violations

plone/schemaeditor/testing.py:26:22: C812 missing trailing comma
plone/schemaeditor/interfaces.py:33:26: C812 missing trailing comma
plone/schemaeditor/interfaces.py:48:76: C812 missing trailing comma
plone/schemaeditor/interfaces.py:52:38: C812 missing trailing comma
plone/schemaeditor/interfaces.py:59:30: C812 missing trailing comma
plone/schemaeditor/interfaces.py:68:22: C812 missing trailing comma
plone/schemaeditor/interfaces.py:150:33: C812 missing trailing comma
plone/schemaeditor/interfaces.py:162:22: C812 missing trailing comma
plone/schemaeditor/interfaces.py:175:23: C812 missing trailing comma
plone/schemaeditor/interfaces.py:190:69: C812 missing trailing comma
plone/schemaeditor/interfaces.py:202:80: C812 missing trailing comma
plone/schemaeditor/interfaces.py:207:72: C812 missing trailing comma
plone/schemaeditor/interfaces.py:215:22: C812 missing trailing comma
plone/schemaeditor/interfaces.py:227:23: C812 missing trailing comma
plone/schemaeditor/utils.py:84:9: T000 Todo note found.
plone/schemaeditor/utils.py:100:18: C812 missing trailing comma
plone/schemaeditor/utils.py:104:12: P002 found "hasattr", consider replacing it
plone/schemaeditor/utils.py:115:16: P002 found "hasattr", consider replacing it
plone/schemaeditor/utils.py:125:18: C812 missing trailing comma
plone/schemaeditor/utils.py:149:26: C812 missing trailing comma
plone/schemaeditor/fields.py:71:58: C812 missing trailing comma
plone/schemaeditor/fields.py:72:14: C812 missing trailing comma
plone/schemaeditor/fields.py:130:9: E303 too many blank lines (2)
plone/schemaeditor/fields.py:227:35: C812 missing trailing comma
plone/schemaeditor/fields.py:228:20: C812 missing trailing comma
plone/schemaeditor/browser/field/fieldset.py:4:1: I001 isort found an import in the wrong position
plone/schemaeditor/browser/field/edit.py:28:1: I004 isort found an unexpected blank line in imports
plone/schemaeditor/browser/field/edit.py:179:12: P002 found "hasattr", consider replacing it
plone/schemaeditor/browser/field/edit.py:187:42: C812 missing trailing comma
plone/schemaeditor/browser/schema/add_field.py:79:76: C812 missing trailing comma
plone/schemaeditor/browser/schema/add_field.py:80:18: C812 missing trailing comma
plone/schemaeditor/browser/schema/add_field.py:112:41: C812 missing trailing comma
plone/schemaeditor/browser/schema/listing.py:55:16: P002 found "hasattr", consider replacing it
plone/schemaeditor/browser/schema/listing.py:109:79: C812 missing trailing comma
plone/schemaeditor/browser/schema/add_fieldset.py:34:79: C812 missing trailing comma
plone/schemaeditor/browser/schema/add_fieldset.py:38:33: C812 missing trailing comma
plone/schemaeditor/browser/schema/add_fieldset.py:54:41: C812 missing trailing comma
plone/schemaeditor/browser/schema/traversal.py:44:21: C812 missing trailing comma
plone/schemaeditor/tests/tests.py:8:1: I001 isort found an import in the wrong position
plone/schemaeditor/tests/tests.py:48:36: C812 missing trailing comma
plone/schemaeditor/tests/test_fields.py:27:19: C812 missing trailing comma
plone/schemaeditor/tests/test_fields.py:35:45: C812 missing trailing comma
plone/schemaeditor/tests/test_fields.py:40:48: C812 missing trailing comma
plone/schemaeditor/tests/test_fields.py:48:44: C812 missing trailing comma
plone/schemaeditor/tests/test_fields.py:53:47: C812 missing trailing comma
plone/schemaeditor/tests/test_robot.py:26:33: C812 missing trailing comma

Follow these instructions to reproduce it locally.

Please sign in to comment.