kopia lustrzana https://github.com/wagtail/wagtail
Test that value.bound_block is available on struct_block templates
rodzic
019778bca8
commit
b041f2e740
|
@ -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):
|
||||
|
|
Ładowanie…
Reference in New Issue