From d5245b1b0cf4384a13f781f636ef550f90d9815a Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Fri, 19 Mar 2010 10:55:09 +0000 Subject: [PATCH] LinesFieldWidget can not use TextAreaFieldWidget anymore as it escapes values now. Add test to avoid regressions git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33913 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Form/tests/testFields.py | 16 +++++++++++++++- product/Formulator/Widget.py | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/product/ERP5Form/tests/testFields.py b/product/ERP5Form/tests/testFields.py index 09dd34fe84..6a63b7db84 100644 --- a/product/ERP5Form/tests/testFields.py +++ b/product/ERP5Form/tests/testFields.py @@ -40,7 +40,7 @@ from Acquisition import aq_base from Products.Formulator.FieldRegistry import FieldRegistry from Products.Formulator.Validator import ValidationError from Products.Formulator.StandardFields import FloatField, StringField,\ -DateTimeField, TextAreaField, CheckBoxField, ListField +DateTimeField, TextAreaField, CheckBoxField, ListField, LinesField from Products.Formulator.MethodField import Method, BoundMethod from Products.Formulator.TALESField import TALESMethod @@ -297,6 +297,19 @@ class TestTextAreaField(ERP5TypeTestCase): .xpath('%s/text:tab' % ODG_XML_WRAPPING_XPATH, namespaces=NSMAP) self.assertTrue(test_value) +class TestLinesField(ERP5TypeTestCase): + + def getTitle(self): + return "Lines Field" + + def afterSetUp(self): + self.field = LinesField('test_field') + self.widget = self.field.widget + + def test_render_view(self): + self.assertEquals(self.field.render_view(value=['My first Line\n', '&My Second Line\tfoo']), + '<div >My first Line<br />\n<br />\n&My Second Line\tfoo</div>') + class TestCheckBoxField(ERP5TypeTestCase): """Tests TextArea field """ @@ -790,6 +803,7 @@ def test_suite(): suite.addTest(unittest.makeSuite(TestStringField)) suite.addTest(unittest.makeSuite(TestDateTimeField)) suite.addTest(unittest.makeSuite(TestTextAreaField)) + suite.addTest(unittest.makeSuite(TestLinesField)) suite.addTest(unittest.makeSuite(TestCheckBoxField)) suite.addTest(unittest.makeSuite(TestListField)) suite.addTest(unittest.makeSuite(TestProxyField)) diff --git a/product/Formulator/Widget.py b/product/Formulator/Widget.py index 33a8bafaad..46478b3ce6 100644 --- a/product/Formulator/Widget.py +++ b/product/Formulator/Widget.py @@ -599,14 +599,17 @@ class LinesTextAreaWidget(TextAreaWidget): def render_view(self, field, value, REQUEST=None, render_prefix=None): if value is None: return '' - elif isinstance(value, (str, unicode)): - value = [value] - return TextAreaWidget.render_view( - self, - field, - string.join(value, field.get_value('view_separator')), - REQUEST, - ) + if isinstance(value, (str, unicode)): + value = value.split('\n') + line_separator = field.get_value('view_separator') + + value_list = [escape(part).replace('\n', line_separator) for part in value] + value = line_separator.join(value_list) + return render_element("div", + css_class=field.get_value('css_class'), + contents=value, + extra=field.get_value('extra')) + def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST, render_prefix, attr_dict, local_name): -- 2.30.9