mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
Render help text for structblocks
This commit is contained in:
parent
8ee2529bc1
commit
7c8f14e545
@ -1,4 +1,7 @@
|
||||
<div class="struct-block">
|
||||
{% if help_text %}
|
||||
<div class="object-help help">{{ help_text }}</div>
|
||||
{% endif %}
|
||||
<ul>
|
||||
{% for child in bound_child_blocks %}
|
||||
<li>
|
||||
|
@ -79,7 +79,8 @@ class BaseStructBlock(Block):
|
||||
]
|
||||
|
||||
return render_to_string('wagtailadmin/block_forms/struct.html', {
|
||||
'bound_child_blocks': bound_child_blocks
|
||||
'bound_child_blocks': bound_child_blocks,
|
||||
'help_text': getattr(self.meta, 'help_text', None),
|
||||
})
|
||||
|
||||
def value_from_datadict(self, data, files, prefix):
|
||||
|
@ -560,6 +560,31 @@ class TestStructBlock(unittest.TestCase):
|
||||
self.assertIn('<input id="mylink-title" name="mylink-title" placeholder="Title" type="text" value="Torchbox" />', html)
|
||||
self.assertIn('<input id="mylink-link" name="mylink-link" placeholder="Link" type="url" value="http://www.torchbox.com" />', html)
|
||||
|
||||
def test_render_form_with_help_text(self):
|
||||
class LinkBlock(blocks.StructBlock):
|
||||
title = blocks.CharBlock()
|
||||
link = blocks.URLBlock()
|
||||
|
||||
class Meta:
|
||||
help_text = "Self-promotion is encouraged"
|
||||
|
||||
block = LinkBlock()
|
||||
html = block.render_form({
|
||||
'title': "Wagtail site",
|
||||
'link': 'http://www.wagtail.io',
|
||||
}, prefix='mylink')
|
||||
|
||||
self.assertIn('<div class="object-help help">Self-promotion is encouraged</div>', html)
|
||||
|
||||
# check it can be overridden in the block constructor
|
||||
block = LinkBlock(help_text="Self-promotion is discouraged")
|
||||
html = block.render_form({
|
||||
'title': "Wagtail site",
|
||||
'link': 'http://www.wagtail.io',
|
||||
}, prefix='mylink')
|
||||
|
||||
self.assertIn('<div class="object-help help">Self-promotion is discouraged</div>', html)
|
||||
|
||||
def test_media_inheritance(self):
|
||||
class ScriptedCharBlock(blocks.CharBlock):
|
||||
media = forms.Media(js=['scripted_char_block.js'])
|
||||
|
Loading…
Reference in New Issue
Block a user