clb_tags.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:django-clubhouse 作者: chazmead 项目源码 文件源码
def render_blocks(context, block_context, parent=None, template=None, **kwargs):
    if isinstance(block_context, basestring):
        try:
            app_label, model_name = block_context.split('.')
            block_context = apps.get_model(app_label, model_name)
        except ValueError:
            error = ('First argument to render_blocks must be the block context '
            ' model, or string in the format "app_label.ModelName"')
            raise TemplateSyntaxError(error)

    if not issubclass(block_context, BlockContext):
        error = ('block_context must be a clubhouse.core.models.BlockContext '
                'instance')
        raise TemplateSyntaxError(error)

    if not parent:
        try:
            parent = context['page'].get_content_model()
        except KeyError:
            error = ('Could not find parent for block context, please provide')
            raise TemplateSyntaxError(error)

    if not template:
        template = block_context.get_template()

    parent_ct = ContentType.objects.get_for_model(parent)
    parent_id = parent.pk

    kwargs.update({
        'blocks': block_context.objects.filter(parent_type=parent_ct,
            parent_id=parent_id).order_by('order'),
        'parent': parent,
        'context_model': block_context
    })
    return select_template([template, 'block_context.html'])\
            .render(Context(kwargs))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号