本文整理汇总了Python中wagtail.wagtailcore.blocks.StructBlock方法的典型用法代码示例。如果您正苦于以下问题:Python blocks.StructBlock方法的具体用法?Python blocks.StructBlock怎么用?Python blocks.StructBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.wagtailcore.blocks
的用法示例。
在下文中一共展示了blocks.StructBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_field_blocks
# 需要导入模块: from wagtail.wagtailcore import blocks [as 别名]
# 或者: from wagtail.wagtailcore.blocks import StructBlock [as 别名]
def get_field_blocks(value):
block = getattr(value, 'block', None)
blocks = [block] if block else []
if isinstance(value, list):
child_blocks = value
if isinstance(block, StructBlock):
if hasattr(value, 'bound_blocks'):
child_blocks = value.bound_blocks.values()
else:
child_blocks = [value.value]
elif isinstance(block, ListBlock):
child_blocks = value.value
else:
child_blocks = []
blocks.extend(chain(*map(get_field_blocks, child_blocks)))
return blocks
示例2: render
# 需要导入模块: from wagtail.wagtailcore import blocks [as 别名]
# 或者: from wagtail.wagtailcore.blocks import StructBlock [as 别名]
def render(self, value, context=None):
"""Only render this content block for users in this segment.
:param value: The value from the block
:type value: dict
:param context: The context containing the request
:type context: dict
:returns: The provided block if matched, otherwise an empty string
:rtype: blocks.StructBlock or empty str
"""
request = context['request']
adapter = get_segment_adapter(request)
user_segments = adapter.get_segments()
if value['segment']:
for segment in user_segments:
if segment.id == int(value['segment']):
return super(PersonalisedStructBlock, self).render(
value, context)
return ""