From ee1f90b3c3b9d83366b512877583e20bdd74847d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 13 Oct 2016 11:14:53 +0200 Subject: [PATCH] fields: always add a "comment-field" class to comment fields (#13582) --- tests/test_fields.py | 8 +++++--- wcs/fields.py | 7 ++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/test_fields.py b/tests/test_fields.py index 6bcf178..ac862c9 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -116,31 +116,33 @@ def test_comment(): field = fields.CommentField(label='Foobar') form = Form() field.add_to_form(form) - assert '

Foobar

' in str(form.render()) + assert '

Foobar

' in str(form.render()) field = fields.CommentField(label='Foo\n\nBar\n\nBaz') form = Form() field.add_to_form(form) assert '

Foo

\n

Bar

\n

Baz

' in str(form.render()) + assert '
Foobar

' in str(form.render()) + assert '

Foobar

' in str(form.render()) # test for proper escaping of substitution variables field = fields.CommentField(label='[foo]') form = Form() field.add_to_form(form) - assert '

1 < 3

' in str(form.render()) + assert '

1 < 3

' in str(form.render()) # test for html content field = fields.CommentField(label='

Foobar

') form = Form() field.add_to_form(form) assert '

Foobar

' in str(form.render()) + assert '
Foobaré

') diff --git a/wcs/fields.py b/wcs/fields.py index 674b90d..857b694 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -500,10 +500,7 @@ class CommentField(Field): description = N_('Comment') def add_to_form(self, form, value = None): - if self.extra_css_class: - extra_css_class = ' class="%s"' % self.extra_css_class - else: - extra_css_class = '' + class_attribute = 'class="comment-field %s"' % (self.extra_css_class or '') if '\n\n' in self.label: label = '

' + re.sub('\n\n+', '

\n

', self.label) + '

' @@ -518,7 +515,7 @@ class CommentField(Field): else: enclosing_tag = 'p' form.widgets.append(HtmlWidget( - htmltext('<%s%s>%s' % (enclosing_tag, extra_css_class, + htmltext('<%s %s>%s' % (enclosing_tag, class_attribute, label, enclosing_tag)))) def add_to_view_form(self, *args): -- 2.9.3