def render_root(*, part, context, **render): assert part._is_bound root_style_name = get_iommi_style_name(part) root_style = get_style(root_style_name) template_name = root_style.base_template content_block_name = root_style.content_block # Render early so that all the binds are forced before we look at all_assets, # since they are populated as a side-effect content = part.__html__(**render) assets = part.iommi_collected_assets() assert template_name, f"{root_style_name} doesn't have a base_template defined" assert content_block_name, f"{root_style_name} doesn't have a content_block defined" title = get_title(part) from iommi.debug import iommi_debug_panel from iommi import Page from iommi.fragment import Container context = dict( container=Container(_name='Container').bind(parent=part), content=content, title=title if title not in (None, MISSING) else '', iommi_debug_panel=iommi_debug_panel(part) if iommi_debug_on() and '_iommi_disable_debug_panel' not in part.get_request().GET else '', assets=assets, **(part.context if isinstance(part, Page) else {}), **context, ) template_string = ('{% extends "' + template_name + '" %} {% block ' + content_block_name + ' %}{{ iommi_debug_panel }}{{ content }}{% endblock %}') return get_template_from_string(template_string).render( context=context, request=part.get_request())
def render_root(*, part, context, **render): assert part._is_bound root_style_name = get_style_name_for(part) root_style = get_style(root_style_name) template_name = root_style.base_template content_block_name = root_style.content_block assert template_name, f"{root_style_name} doesn't have a base_template defined" assert content_block_name, f"{root_style_name} doesn't have a content_block defined" title = getattr(part, 'title', None) if title is None: parts = getattr(part, 'parts', None) if parts is not None: for p in parts.values(): title = getattr(p, 'title', None) if title is not None: break from iommi.debug import iommi_debug_panel from iommi import Page from iommi.fragment import Container context = dict( container=Container(_name='Container').bind(parent=part), content=part.__html__(**render), title=title if title not in (None, MISSING) else '', iommi_debug_panel=iommi_debug_panel(part) if iommi_debug_on() else '', **(part.context if isinstance(part, Page) else {}), **context, ) template_string = '{% extends "' + template_name + '" %} {% block ' + content_block_name + ' %}{{ iommi_debug_panel }}{{ content }}{% endblock %}' return get_template_from_string(template_string).render( context=context, request=part.get_request())