0003-blocks-display-label-as-title-47907.patch
tests/test_form_pages/test_block.py | ||
---|---|---|
459 | 459 |
resp = resp.follow() |
460 | 460 | |
461 | 461 | |
462 |
def test_block_label(pub, blocks_feature): |
|
463 |
FormDef.wipe() |
|
464 |
BlockDef.wipe() |
|
465 | ||
466 |
block = BlockDef() |
|
467 |
block.name = 'foobar' |
|
468 |
block.fields = [ |
|
469 |
fields.StringField(id='123', required=True, label='Test', type='string'), |
|
470 |
] |
|
471 |
block.store() |
|
472 | ||
473 |
formdef = FormDef() |
|
474 |
formdef.name = 'form title' |
|
475 |
formdef.fields = [ |
|
476 |
fields.BlockField(id='1', label='Block Label', type='block:foobar'), |
|
477 |
] |
|
478 |
formdef.store() |
|
479 | ||
480 |
app = get_app(pub) |
|
481 |
resp = app.get(formdef.get_url()) |
|
482 |
assert '<h4>Block Label<span title="This field is required." class="required">*</span></h4>' in resp.text |
|
483 | ||
484 | ||
462 | 485 |
def test_block_multipage(pub, blocks_feature): |
463 | 486 |
FormDef.wipe() |
464 | 487 |
BlockDef.wipe() |
wcs/blocks.py | ||
---|---|---|
19 | 19 |
import xml.etree.ElementTree as ET |
20 | 20 | |
21 | 21 |
from quixote import get_request, get_publisher |
22 |
from quixote.html import htmltext |
|
22 | 23 | |
23 | 24 |
from .qommon import _, N_, misc |
24 | 25 |
from .qommon.form import CompositeWidget, WidgetList |
... | ... | |
334 | 335 |
if widget.has_error(): |
335 | 336 |
has_error = True |
336 | 337 |
return has_error |
338 | ||
339 |
def render_title(self, title): |
|
340 |
if not title: |
|
341 |
return '' |
|
342 |
if self.required: |
|
343 |
title += htmltext('<span title="%s" class="required">*</span>') % _( |
|
344 |
'This field is required.') |
|
345 |
return htmltext('<h4>%s</h4>') % title |
|
337 |
- |