当前位置: 首页>>代码示例>>Python>>正文


Python blocks.StructBlock方法代码示例

本文整理汇总了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 
开发者ID:cfpb,项目名称:wagtail-inventory,代码行数:21,代码来源:helpers.py

示例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 "" 
开发者ID:LabD,项目名称:wagtail-personalisation,代码行数:24,代码来源:blocks.py


注:本文中的wagtail.wagtailcore.blocks.StructBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。