def __render(self, context=None): rendered_data = '' if isinstance(context, template.Context) or isinstance(context, template.RequestContext): context = context.flatten() code_renderer = CodeRenderer() for item in self.data: bl_class = get_block_class_for(item.get('type', 'INVALID_PLUGIN_WITH_NO_TYPE')) if bl_class: instance = bl_class(item, code_renderer) rendered_data = rendered_data + instance.render(context) return code_renderer, rendered_data
def get_rendered_children(self, obj, context): if obj.get('children') is not None: total_childes = [] for child in obj.get('children'): bl_class = get_block_class_for(child.get('type', 'INVALID_PLUGIN_WITH_NO_TYPE')) if bl_class: instance = bl_class(self.codeRenderer) rendered_child = instance.render(child, context) total_childes.append({ 'child': child, 'rendered': rendered_child }) return total_childes return []
def get_rendered_children(self, context=None): """ Blocks might have child blocks. Render children. :param context: dict context for children :return: safe str - Rendered string """ from hypereditor.blocks import get_block_class_for rendered_child = '' if self.obj.get('children') is not None: for child in self.obj.get('children'): bl_class = get_block_class_for( child.get('type', 'INVALID_PLUGIN_WITH_NO_TYPE')) if bl_class: instance = bl_class(child, self.codeRenderer) rendered_child = rendered_child + instance.render(context) return mark_safe(rendered_child)
def render(self, context): try: value = self.block_var.resolve(context) except template.VariableDoesNotExist: return '' if isinstance(value, dict): # its an preview code_renderer = CodeRenderer() bl_class = get_block_class_for( value.get('type', 'INVALID_PLUGIN_WITH_NO_TYPE')) if bl_class: instance = bl_class(value, code_renderer) return instance.render(context) else: return '' elif isinstance(value, str): try: value = HyperFieldResponse.from_str(value) return value.render(context) except Exception as e: print(e) return '' else: return value.render(context)