0001-fields-always-add-a-comment-field-class-to-comment-f.patch
tests/test_fields.py | ||
---|---|---|
116 | 116 |
field = fields.CommentField(label='Foobar') |
117 | 117 |
form = Form() |
118 | 118 |
field.add_to_form(form) |
119 |
assert '<p>Foobar</p>' in str(form.render()) |
|
119 |
assert '<p class="comment-field ">Foobar</p>' in str(form.render())
|
|
120 | 120 | |
121 | 121 |
field = fields.CommentField(label='Foo\n\nBar\n\nBaz') |
122 | 122 |
form = Form() |
123 | 123 |
field.add_to_form(form) |
124 | 124 |
assert '<p>Foo</p>\n<p>Bar</p>\n<p>Baz</p>' in str(form.render()) |
125 |
assert '<div class="comment-field "' in str(form.render()) |
|
125 | 126 | |
126 | 127 |
# test for variable substitution |
127 | 128 |
pub.substitutions.feed(MockSubstitutionVariables()) |
128 | 129 |
field = fields.CommentField(label='[bar]') |
129 | 130 |
form = Form() |
130 | 131 |
field.add_to_form(form) |
131 |
assert '<p>Foobar</p>' in str(form.render()) |
|
132 |
assert '<p class="comment-field ">Foobar</p>' in str(form.render())
|
|
132 | 133 | |
133 | 134 |
# test for proper escaping of substitution variables |
134 | 135 |
field = fields.CommentField(label='[foo]') |
135 | 136 |
form = Form() |
136 | 137 |
field.add_to_form(form) |
137 |
assert '<p>1 < 3</p>' in str(form.render()) |
|
138 |
assert '<p class="comment-field ">1 < 3</p>' in str(form.render())
|
|
138 | 139 | |
139 | 140 |
# test for html content |
140 | 141 |
field = fields.CommentField(label='<p>Foobar</p>') |
141 | 142 |
form = Form() |
142 | 143 |
field.add_to_form(form) |
143 | 144 |
assert '<p>Foobar</p>' in str(form.render()) |
145 |
assert '<div class="comment-field "' in str(form.render()) |
|
144 | 146 |
assert field.unhtmled_label == 'Foobar' |
145 | 147 | |
146 | 148 |
field = fields.CommentField(label='<p>Foobaré</p>') |
wcs/fields.py | ||
---|---|---|
500 | 500 |
description = N_('Comment') |
501 | 501 | |
502 | 502 |
def add_to_form(self, form, value = None): |
503 |
if self.extra_css_class: |
|
504 |
extra_css_class = ' class="%s"' % self.extra_css_class |
|
505 |
else: |
|
506 |
extra_css_class = '' |
|
503 |
class_attribute = 'class="comment-field %s"' % (self.extra_css_class or '') |
|
507 | 504 | |
508 | 505 |
if '\n\n' in self.label: |
509 | 506 |
label = '<p>' + re.sub('\n\n+', '</p>\n<p>', self.label) + '</p>' |
... | ... | |
518 | 515 |
else: |
519 | 516 |
enclosing_tag = 'p' |
520 | 517 |
form.widgets.append(HtmlWidget( |
521 |
htmltext('<%s%s>%s</%s>' % (enclosing_tag, extra_css_class,
|
|
518 |
htmltext('<%s %s>%s</%s>' % (enclosing_tag, class_attribute,
|
|
522 | 519 |
label, enclosing_tag)))) |
523 | 520 | |
524 | 521 |
def add_to_view_form(self, *args): |
525 |
- |