本文整理汇总了Python中wagtail.core.blocks.URLBlock方法的典型用法代码示例。如果您正苦于以下问题:Python blocks.URLBlock方法的具体用法?Python blocks.URLBlock怎么用?Python blocks.URLBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.core.blocks
的用法示例。
在下文中一共展示了blocks.URLBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_unknown_field
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_render_unknown_field(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
link = blocks.URLBlock()
block = LinkBlock()
html = block.render(block.to_python({
'title': "Wagtail site",
'link': 'http://www.wagtail.io',
'image': 10,
}))
self.assertIn('<dt>title</dt>', html)
self.assertIn('<dd>Wagtail site</dd>', html)
self.assertIn('<dt>link</dt>', html)
self.assertIn('<dd>http://www.wagtail.io</dd>', html)
# Don't render the extra item
self.assertNotIn('<dt>image</dt>', html)
示例2: test_get_form_context
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_get_form_context(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
link = blocks.URLBlock()
block = LinkBlock()
context = block.get_form_context(block.to_python({
'title': "Wagtail site",
'link': 'http://www.wagtail.io',
}), prefix='mylink')
self.assertTrue(isinstance(context['children'], collections.OrderedDict))
self.assertEqual(len(context['children']), 2)
self.assertTrue(isinstance(context['children']['title'], blocks.BoundBlock))
self.assertEqual(context['children']['title'].value, "Wagtail site")
self.assertTrue(isinstance(context['children']['link'], blocks.BoundBlock))
self.assertEqual(context['children']['link'].value, 'http://www.wagtail.io')
self.assertEqual(context['block_definition'], block)
self.assertEqual(context['prefix'], 'mylink')
示例3: test_custom_render_form_template
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_custom_render_form_template(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock(required=False)
link = blocks.URLBlock(required=False)
class Meta:
form_template = 'tests/block_forms/struct_block_form_template.html'
block = LinkBlock()
html = block.render_form(block.to_python({
'title': "Wagtail site",
'link': 'http://www.wagtail.io',
}), prefix='mylink')
self.assertIn('<div>Hello</div>', html)
self.assertHTMLEqual('<div>Hello</div>', html)
self.assertTrue(isinstance(html, SafeText))
示例4: test_custom_render_form_template_jinja
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_custom_render_form_template_jinja(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock(required=False)
link = blocks.URLBlock(required=False)
class Meta:
form_template = 'tests/jinja2/struct_block_form_template.html'
block = LinkBlock()
html = block.render_form(block.to_python({
'title': "Wagtail site",
'link': 'http://www.wagtail.io',
}), prefix='mylink')
self.assertIn('<div>Hello</div>', html)
self.assertHTMLEqual('<div>Hello</div>', html)
self.assertTrue(isinstance(html, SafeText))
示例5: test_render_form_uses_default_value
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_render_form_uses_default_value(self):
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock(default="Torchbox")
link = blocks.URLBlock(default="http://www.torchbox.com")
block = LinkBlock()
html = block.render_form(block.to_python({}), prefix='mylink')
self.assertInHTML(
'<input id="mylink-title" name="mylink-title" placeholder="Title" type="text" value="Torchbox" />', html
)
self.assertInHTML(
(
'<input id="mylink-link" name="mylink-link" placeholder="Link"'
' type="url" value="http://www.torchbox.com" />'
),
html
)
示例6: test_render_form_with_help_text
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
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(block.to_python({
'title': "Wagtail site",
'link': 'http://www.wagtail.io',
}), prefix='mylink')
self.assertInHTML('<div class="help"><span class="icon-help-inverse" aria-hidden="true"></span> 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(block.to_python({
'title': "Wagtail site",
'link': 'http://www.wagtail.io',
}), prefix='mylink')
self.assertInHTML('<div class="help"><span class="icon-help-inverse" aria-hidden="true"></span> Self-promotion is discouraged</div>', html)
示例7: test_initialisation_from_subclass
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_initialisation_from_subclass(self):
class LinkStructValue(blocks.StructValue):
def url(self):
return self.get('page') or self.get('link')
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
page = blocks.PageChooserBlock(required=False)
link = blocks.URLBlock(required=False)
class Meta:
value_class = LinkStructValue
block = LinkBlock()
self.assertEqual(list(block.child_blocks.keys()), ['title', 'page', 'link'])
block_value = block.to_python({'title': 'Website', 'link': 'https://website.com'})
self.assertIsInstance(block_value, LinkStructValue)
default_value = block.get_default()
self.assertIsInstance(default_value, LinkStructValue)
示例8: render
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [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',
},
])
示例9: render_form
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [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
示例10: test_html_declarations
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [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
)
示例11: test_html_declarations_uses_default
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [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
)
示例12: test_render_with_classname_via_kwarg
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_render_with_classname_via_kwarg(self):
"""form_classname from kwargs to be used as an additional class when rendering list block"""
class LinkBlock(blocks.StructBlock):
title = blocks.CharBlock()
link = blocks.URLBlock()
block = blocks.ListBlock(LinkBlock, form_classname='special-list-class')
html = block.render_form([
{
'title': "Wagtail",
'link': 'http://www.wagtail.io',
},
{
'title': "Django",
'link': 'http://www.djangoproject.com',
},
], prefix='links')
# including leading space to ensure class name gets added correctly
self.assertEqual(html.count(' special-list-class'), 1)
示例13: test_validation_errors
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_validation_errors(self):
class ValidatedBlock(blocks.StreamBlock):
char = blocks.CharBlock()
url = blocks.URLBlock()
block = ValidatedBlock()
value = blocks.StreamValue(block, [
('char', ''),
('char', 'foo'),
('url', 'http://example.com/'),
('url', 'not a url'),
])
with self.assertRaises(ValidationError) as catcher:
block.clean(value)
self.assertEqual(catcher.exception.params, {
0: ['This field is required.'],
3: ['Enter a valid URL.'],
})
示例14: test_min_num_validation_errors
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_min_num_validation_errors(self):
class ValidatedBlock(blocks.StreamBlock):
char = blocks.CharBlock()
url = blocks.URLBlock()
block = ValidatedBlock(min_num=1)
value = blocks.StreamValue(block, [])
with self.assertRaises(ValidationError) as catcher:
block.clean(value)
self.assertEqual(catcher.exception.params, {
'__all__': ['The minimum number of items is 1']
})
# a value with >= 1 blocks should pass validation
value = blocks.StreamValue(block, [('char', 'foo')])
self.assertTrue(block.clean(value))
示例15: test_max_num_validation_errors
# 需要导入模块: from wagtail.core import blocks [as 别名]
# 或者: from wagtail.core.blocks import URLBlock [as 别名]
def test_max_num_validation_errors(self):
class ValidatedBlock(blocks.StreamBlock):
char = blocks.CharBlock()
url = blocks.URLBlock()
block = ValidatedBlock(max_num=1)
value = blocks.StreamValue(block, [
('char', 'foo'),
('char', 'foo'),
('url', 'http://example.com/'),
('url', 'http://example.com/'),
])
with self.assertRaises(ValidationError) as catcher:
block.clean(value)
self.assertEqual(catcher.exception.params, {
'__all__': ['The maximum number of items is 1']
})
# a value with 1 block should pass validation
value = blocks.StreamValue(block, [('char', 'foo')])
self.assertTrue(block.clean(value))