0001-fields-render-template-for-title-and-subtitle-36620.patch
tests/test_fields.py | ||
---|---|---|
162 | 162 |
field.add_to_form(form) |
163 | 163 |
assert '<h3 data-field-id="None" class="test">Foobar</h3>' in str(form.render()) |
164 | 164 | |
165 |
# test for variable substitution |
|
166 |
pub.substitutions.feed(MockSubstitutionVariables()) |
|
167 |
field = fields.TitleField(label='{{ bar }}') |
|
168 |
form = Form(use_tokens=False) |
|
169 |
field.add_to_form(form) |
|
170 |
assert '<h3 data-field-id="None">Foobar</h3>' in str(form.render()) |
|
171 | ||
165 | 172 |
def test_subtitle(): |
166 | 173 |
field = fields.SubtitleField(label='Foobar') |
167 | 174 |
form = Form(use_tokens=False) |
... | ... | |
173 | 180 |
field.add_to_form(form) |
174 | 181 |
assert '<h4 data-field-id="None" class="test">Foobar</h4>' in str(form.render()) |
175 | 182 | |
183 |
# test for variable substitution |
|
184 |
pub.substitutions.feed(MockSubstitutionVariables()) |
|
185 |
field = fields.SubtitleField(label='{{ bar }}') |
|
186 |
form = Form(use_tokens=False) |
|
187 |
field.add_to_form(form) |
|
188 |
assert '<h4 data-field-id="None">Foobar</h4>' in str(form.render()) |
|
189 | ||
176 | 190 |
def test_comment(): |
177 | 191 |
field = fields.CommentField(label='Foobar') |
178 | 192 |
form = Form(use_tokens=False) |
wcs/fields.py | ||
---|---|---|
569 | 569 |
class TitleField(Field): |
570 | 570 |
key = 'title' |
571 | 571 |
description = N_('Title') |
572 |
html_template = '<h3%s>%s</h3>' |
|
572 | 573 | |
573 | 574 |
def add_to_form(self, form, value = None): |
575 |
import wcs.workflows |
|
574 | 576 |
extra_attributes = ' data-field-id="%s"' % self.id |
575 | 577 |
if self.extra_css_class: |
576 | 578 |
extra_attributes += ' class="%s"' % self.extra_css_class |
577 |
widget = HtmlWidget(htmltext('<h3%s>%s</h3>' % (extra_attributes, self.label))) |
|
579 |
label = wcs.workflows.template_on_html_string(self.label) |
|
580 |
widget = HtmlWidget(htmltext(self.html_template % (extra_attributes, label))) |
|
578 | 581 |
form.widgets.append(widget) |
579 | 582 |
return widget |
580 | 583 |
add_to_view_form = add_to_form |
... | ... | |
597 | 600 |
class SubtitleField(TitleField): |
598 | 601 |
key = 'subtitle' |
599 | 602 |
description = N_('Subtitle') |
600 | ||
601 |
def add_to_form(self, form, value = None): |
|
602 |
extra_attributes = ' data-field-id="%s"' % self.id |
|
603 |
if self.extra_css_class: |
|
604 |
extra_attributes += ' class="%s"' % self.extra_css_class |
|
605 |
widget = HtmlWidget(htmltext('<h4%s>%s</h4>' % (extra_attributes, self.label))) |
|
606 |
form.widgets.append(widget) |
|
607 |
return widget |
|
608 |
add_to_view_form = add_to_form |
|
603 |
html_template = '<h4%s>%s</h4>' |
|
609 | 604 | |
610 | 605 |
register_field_class(SubtitleField) |
611 | 606 | |
612 |
- |