mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-05 22:14:45 +00:00
Test that value.bound_block is available on struct_block templates
This commit is contained in:
parent
019778bca8
commit
b041f2e740
3 changed files with 21 additions and 0 deletions
|
|
@ -12,3 +12,11 @@ class LinkBlock(blocks.StructBlock):
|
|||
|
||||
class Meta:
|
||||
template = 'tests/blocks/link_block.html'
|
||||
|
||||
|
||||
class SectionBlock(blocks.StructBlock):
|
||||
title = blocks.CharBlock()
|
||||
body = blocks.RichTextBlock()
|
||||
|
||||
class Meta:
|
||||
template = 'tests/blocks/section_block.html'
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<h1>{{ value.title }}</h1>{{ value.bound_blocks.body.render }}
|
||||
|
|
@ -13,6 +13,8 @@ from wagtail.wagtailcore import blocks
|
|||
from wagtail.wagtailcore.rich_text import RichText
|
||||
from wagtail.wagtailcore.models import Page
|
||||
|
||||
from wagtail.tests.testapp.blocks import SectionBlock
|
||||
|
||||
import base64
|
||||
|
||||
|
||||
|
|
@ -714,6 +716,16 @@ class TestStructBlock(SimpleTestCase):
|
|||
with self.assertRaises(ValidationError):
|
||||
block.clean(value)
|
||||
|
||||
def test_bound_blocks_are_available_on_template(self):
|
||||
"""
|
||||
Test that we are able to use value.bound_blocks within templates
|
||||
to access a child block's own HTML rendering
|
||||
"""
|
||||
block = SectionBlock()
|
||||
value = block.to_python({'title': 'Hello', 'body': '<i>italic</i> world'})
|
||||
result = block.render(value)
|
||||
self.assertEqual(result, """<h1>Hello</h1><div class="rich-text"><i>italic</i> world</div>""")
|
||||
|
||||
|
||||
class TestListBlock(unittest.TestCase):
|
||||
def test_initialise_with_class(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue