本文整理匯總了Python中wagtail.core.blocks.ListBlock方法的典型用法代碼示例。如果您正苦於以下問題:Python blocks.ListBlock方法的具體用法?Python blocks.ListBlock怎麽用?Python blocks.ListBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.core.blocks
的用法示例。
在下文中一共展示了blocks.ListBlock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def render(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
link = blocks.URLBlock()
block = blocks.ListBlock(LinkBlock())
return block.render([
{
'title': "Wagtail",
'link': 'http://www.wagtail.io',
},
{
'title': "Django",
'link': 'http://www.djangoproject.com',
},
])
示例2: render_form
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def render_form(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
link = blocks.URLBlock()
block = blocks.ListBlock(LinkBlock)
html = block.render_form([
{
'title': "Wagtail",
'link': 'http://www.wagtail.io',
},
{
'title': "Django",
'link': 'http://www.djangoproject.com',
},
], prefix='links')
return html
示例3: test_html_declarations
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_html_declarations(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
link = blocks.URLBlock()
block = blocks.ListBlock(LinkBlock)
html = block.html_declarations()
self.assertTagInTemplateScript(
'<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" placeholder="Title" type="text" />',
html
)
self.assertTagInTemplateScript(
'<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" placeholder="Link" type="url" />',
html
)
示例4: test_html_declarations_uses_default
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_html_declarations_uses_default(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock(default="Github")
link = blocks.URLBlock(default="http://www.github.com")
block = blocks.ListBlock(LinkBlock)
html = block.html_declarations()
self.assertTagInTemplateScript(
(
'<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" placeholder="Title"'
' type="text" value="Github" />'
),
html
)
self.assertTagInTemplateScript(
(
'<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" placeholder="Link"'
' type="url" value="http://www.github.com" />'
),
html
)
示例5: test_default_default
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_default_default(self):
"""
if no explicit 'default' is set on the ListBlock, it should fall back on
a single instance of the child block in its default state.
"""
class ShoppingListBlock(blocks.StructBlock):
shop = blocks.CharBlock()
items = blocks.ListBlock(blocks.CharBlock(default='chocolate'))
block = ShoppingListBlock()
# the value here does not specify an 'items' field, so this should revert to the ListBlock's default
form_html = block.render_form(block.to_python({'shop': 'Tesco'}), prefix='shoppinglist')
self.assertIn(
'<input type="hidden" name="shoppinglist-items-count" id="shoppinglist-items-count" value="1">',
form_html
)
self.assertIn('value="chocolate"', form_html)
示例6: test_system_checks_recurse_into_lists
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_system_checks_recurse_into_lists(self):
failing_block = blocks.RichTextBlock()
block = blocks.StreamBlock([
('paragraph_list', blocks.ListBlock(
blocks.StructBlock([
('heading', blocks.CharBlock()),
('rich text', failing_block),
])
))
])
errors = block.check()
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0].id, 'wagtailcore.E001')
self.assertEqual(errors[0].hint, "Block names cannot contain spaces")
self.assertEqual(errors[0].obj, failing_block)
示例7: test_initialise_with_class
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_initialise_with_class(self):
block = blocks.ListBlock(blocks.CharBlock)
# Child block should be initialised for us
self.assertIsInstance(block.child_block, blocks.CharBlock)
示例8: test_initialise_with_instance
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_initialise_with_instance(self):
child_block = blocks.CharBlock()
block = blocks.ListBlock(child_block)
self.assertEqual(block.child_block, child_block)
示例9: test_render_calls_block_render_on_children
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_render_calls_block_render_on_children(self):
"""
The default rendering of a ListBlock should invoke the block's render method
on each child, rather than just outputting the child value as a string.
"""
block = blocks.ListBlock(
blocks.CharBlock(template='tests/blocks/heading_block.html')
)
html = block.render(["Hello world!", "Goodbye world!"])
self.assertIn('<h1>Hello world!</h1>', html)
self.assertIn('<h1>Goodbye world!</h1>', html)
示例10: test_render_passes_context_to_children
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_render_passes_context_to_children(self):
"""
Template context passed to the render method should be passed on
to the render method of the child block.
"""
block = blocks.ListBlock(
blocks.CharBlock(template='tests/blocks/heading_block.html')
)
html = block.render(["Bonjour le monde!", "Au revoir le monde!"], context={
'language': 'fr',
})
self.assertIn('<h1 lang="fr">Bonjour le monde!</h1>', html)
self.assertIn('<h1 lang="fr">Au revoir le monde!</h1>', html)
示例11: test_media_inheritance
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_media_inheritance(self):
class ScriptedCharBlock(blocks.CharBlock):
media = forms.Media(js=['scripted_char_block.js'])
block = blocks.ListBlock(ScriptedCharBlock())
self.assertIn('scripted_char_block.js', ''.join(block.all_media().render_js()))
示例12: test_html_declaration_inheritance
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_html_declaration_inheritance(self):
class CharBlockWithDeclarations(blocks.CharBlock):
def html_declarations(self):
return '<script type="text/x-html-template">hello world</script>'
block = blocks.ListBlock(CharBlockWithDeclarations())
self.assertIn('<script type="text/x-html-template">hello world</script>', block.all_html_declarations())
示例13: test_value_omitted_from_data
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_value_omitted_from_data(self):
block = blocks.ListBlock(blocks.CharBlock())
# overall value is considered present in the form if the 'count' field is present
self.assertFalse(block.value_omitted_from_data({'mylist-count': '0'}, {}, 'mylist'))
self.assertFalse(block.value_omitted_from_data({
'mylist-count': '1',
'mylist-0-value': 'hello', 'mylist-0-deleted': '', 'mylist-0-order': '0'
}, {}, 'mylist'))
self.assertTrue(block.value_omitted_from_data({'nothing-here': 'nope'}, {}, 'mylist'))
示例14: test_ordering_in_form_submission_uses_order_field
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_ordering_in_form_submission_uses_order_field(self):
block = blocks.ListBlock(blocks.CharBlock())
# check that items are ordered by the 'order' field, not the order they appear in the form
post_data = {'shoppinglist-count': '3'}
for i in range(0, 3):
post_data.update({
'shoppinglist-%d-deleted' % i: '',
'shoppinglist-%d-order' % i: str(2 - i),
'shoppinglist-%d-value' % i: "item %d" % i
})
block_value = block.value_from_datadict(post_data, {}, 'shoppinglist')
self.assertEqual(block_value[2], "item 0")
示例15: test_ordering_in_form_submission_is_numeric
# 需要導入模塊: from wagtail.core import blocks [as 別名]
# 或者: from wagtail.core.blocks import ListBlock [as 別名]
def test_ordering_in_form_submission_is_numeric(self):
block = blocks.ListBlock(blocks.CharBlock())
# check that items are ordered by 'order' numerically, not alphabetically
post_data = {'shoppinglist-count': '12'}
for i in range(0, 12):
post_data.update({
'shoppinglist-%d-deleted' % i: '',
'shoppinglist-%d-order' % i: str(i),
'shoppinglist-%d-value' % i: "item %d" % i
})
block_value = block.value_from_datadict(post_data, {}, 'shoppinglist')
self.assertEqual(block_value[2], "item 2")