本文整理匯總了Python中wagtail.wagtailcore.blocks.ListBlock方法的典型用法代碼示例。如果您正苦於以下問題:Python blocks.ListBlock方法的具體用法?Python blocks.ListBlock怎麽用?Python blocks.ListBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailcore.blocks
的用法示例。
在下文中一共展示了blocks.ListBlock方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_field_blocks
# 需要導入模塊: from wagtail.wagtailcore import blocks [as 別名]
# 或者: from wagtail.wagtailcore.blocks import ListBlock [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