當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。