def bind(self, *, parent=None, request=None): assert parent is None or parent._is_bound assert not self._is_bound result = copy.copy(self) if parent: is_root = False iommi_style = get_iommi_style_name(parent) else: is_root = True iommi_style = get_iommi_style_name(self) result = apply_style(iommi_style, result, is_root) result._declared = self del self # to prevent mistakes when changing the code below if parent is None: result._request = request if result._name is None: result._name = 'root' result._iommi_collected_assets = {} result._parent = parent result._bound_members = Struct() result._is_bound = True evaluate_parameters = { **(parent.iommi_evaluate_parameters() if parent is not None else {}), **result.own_evaluate_parameters(), 'traversable': result, } if parent is None: evaluate_parameters['request'] = request result._evaluate_parameters = evaluate_parameters if hasattr(result, 'include'): include = evaluate_strict(result.include, **evaluate_parameters) if not bool(include): return None result.include = True result.on_bind() # on_bind has a chance to hide itself if result.include is False: return None if hasattr(result, 'attrs'): result.attrs = evaluate_attrs(result, **result.iommi_evaluate_parameters()) evaluated_attributes = [k for k, v in items(result.get_declared('refinable_members')) if is_evaluated_refinable(v)] evaluate_members(result, evaluated_attributes, **evaluate_parameters) if hasattr(result, 'extra_evaluated'): result.extra_evaluated = evaluate_strict_container(result.extra_evaluated or {}, **evaluate_parameters) return result
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())