Commit d5245b1b authored by Nicolas Delaby's avatar Nicolas Delaby

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
parent da170af1
No related merge requests found
......@@ -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&amp;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))
......
......@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment