Commit b386cb8e authored by Nicolas Delaby's avatar Nicolas Delaby

Replace new lines by <br/> and escape string value for

TextAreaWidget.render_view (read-only)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33908 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 98b68a90
...@@ -269,6 +269,18 @@ class TestTextAreaField(ERP5TypeTestCase): ...@@ -269,6 +269,18 @@ class TestTextAreaField(ERP5TypeTestCase):
self.field = TextAreaField('test_field') self.field = TextAreaField('test_field')
self.widget = self.field.widget self.widget = self.field.widget
def test_render_view(self):
self.field.values['default'] = 'My first Line\n&My Second Line\tfoo'
self.assertEquals('<div >My first Line<br/><br/>&amp;My Second Line\tfoo</div>',
self.field.render_view(value=['My first Line\n', '&My Second Line\tfoo']))
editable_mode = self.portal.REQUEST.get('editable_mode', 1)
self.portal.REQUEST.set('editable_mode', 0)
try:
self.assertEquals('<div >My first Line<br/>&amp;My Second Line\tfoo</div>',
self.field.render(REQUEST=self.portal.REQUEST))
finally:
self.portal.REQUEST.set('editable_mode', editable_mode)
def test_render_odt(self): def test_render_odt(self):
self.field.values['default'] = 'My first Line\nMy Second Line\tfoo' self.field.values['default'] = 'My first Line\nMy Second Line\tfoo'
self.assertEquals('text:line-break', self.assertEquals('text:line-break',
......
...@@ -531,6 +531,13 @@ class TextAreaWidget(Widget): ...@@ -531,6 +531,13 @@ class TextAreaWidget(Widget):
extra=field.get_value('extra')) extra=field.get_value('extra'))
def render_view(self, field, value, REQUEST, render_prefix=None): def render_view(self, field, value, REQUEST, render_prefix=None):
if value is None:
return ''
if not isinstance(value, (tuple, list)):
value = value.split('\n')
line_separator = '<br/>'
value_list = [escape(part).replace('\n', line_separator) for part in value]
value = line_separator.join(value_list)
return render_element("div", return render_element("div",
css_class=field.get_value('css_class'), css_class=field.get_value('css_class'),
contents=value, contents=value,
......
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