0
0
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:
Matt Westcott 2015-06-08 14:00:50 +01:00
parent 8ee2529bc1
commit 7c8f14e545
3 changed files with 30 additions and 1 deletions

View File

@ -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>

View File

@ -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):

View File

@ -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'])