diff --git a/product/ERP5Type/Accessor/TypeDefinition.py b/product/ERP5Type/Accessor/TypeDefinition.py index 948770665f2634b8e7b3884779b37759d768f18a..ca986aefd6e5690f839a1fb921b93507b5624f2d 100644 --- a/product/ERP5Type/Accessor/TypeDefinition.py +++ b/product/ERP5Type/Accessor/TypeDefinition.py @@ -92,9 +92,10 @@ def asString(value): if value is None: result = '' else: - result = str(value) - if isinstance(result, unicode): - result = result.encode('utf-8') + if isinstance(value, unicode): + result = value.encode('utf-8') + else: + result = str(value) except TypeError: result = type_definition['string']['default'] return result diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index 55389f24b19960bff816e78dd25567abaf628bc6..1452fc0f4fd084a36b5530ea7a3512e1bf81a445 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -1,5 +1,5 @@ ############################################################################## -# +# -*- coding: utf8 -*- # Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved. # Yoshinori Okuji <yo@nexedi.com> # @@ -944,6 +944,21 @@ class TestPropertySheet: self.assertTrue(person.hasProperty('dummy_ps_prop')) self.assertEquals('a value', person.getDummyPsProp()) + # string accessors converts the data type, if provided an unicode, it + # will store an utf-8 encoded string + person.setDummyPsProp(u'type conv茅rsion') + self.assertEquals('type conv茅rsion', person.getDummyPsProp()) + # if provided anything else, it will store it's string representation + person.setDummyPsProp(1) + self.assertEquals('1', person.getDummyPsProp()) + + class Dummy: + def __str__(self): + return 'string representation' + person.setDummyPsProp(Dummy()) + self.assertEquals('string representation', person.getDummyPsProp()) + + def test_17_WorkflowStateAccessor(self): """Tests for workflow state. assumes that validation state is chained to the Person portal type and that this workflow has 'validation_state' as