def children( self, parent_item: 'TreeItemBase', navigation_type: str, use_template: str, context: Context ) -> str: """Builds and returns site tree item children structure for 'sitetree_children' tag. :param parent_item: :param navigation_type: menu, sitetree :param use_template: :param context: """ # Resolve parent item and current tree alias. parent_item = self.resolve_var(parent_item, context) tree_alias, tree_items = self.get_sitetree(parent_item.tree.alias) # Mark path to current item. self.tree_climber(tree_alias, self.get_tree_current_item(tree_alias)) tree_items = self.get_children(tree_alias, parent_item) tree_items = self.filter_items(tree_items, navigation_type) tree_items = self.apply_hook(tree_items, f'{navigation_type}.children') self.update_has_children(tree_alias, tree_items, navigation_type) my_template = get_template(use_template) context.push() context['sitetree_items'] = tree_items rendered = my_template.render(context.flatten()) context.pop() return rendered
def healed_context(context): """ .. testcase:: HealedContextTestCase """ if not isinstance(context, BaseContext): context = Context(context) original_context_length = len(context.dicts) yield context ctx_length = len(context.dicts) while ctx_length > 1 and ctx_length > original_context_length: logger.debug('Removing excess context dicts (target size {0},' 'working size {1})'.format(original_context_length, ctx_length)) context.pop() ctx_length = len(context.dicts)
def post(self, request): form = SearchForm(request.POST) if form.is_valid(): query = form.cleaned_data['query'] tweets = Tweet.objects.filter(text__icontains=query) context = Context({"query": query,"tweets": tweets}) return_str = render_to_string('a_tweet_search.html', context.pop()) return HttpResponse(json.dumps(return_str), content_type="application/json") else: HttpResponseRedirect("/search")
jingo.register.env, compiled_node, {} ).render(context)) try: context['compress_forced'] = True compiled_node = env.compile(jinja2.nodes.Template([node])) result = Template.from_code( env, compiled_node, {}).render(context) except Exception, e: raise CommandError("An error occured during rendering %s: " "%s" % (template.template_name, e)) offline_manifest[key] = result context.pop() results.append(result) count += 1 write_offline_manifest(offline_manifest) log.write("done\nCompressed %d block(s) from %d template(s).\n" % (count, len(compressor_nodes))) return count, results def get_nodelist(self, node): if (isinstance(node, IfNode) and hasattr(node, 'nodelist_true') and hasattr(node, 'nodelist_false')): return node.nodelist_true + node.nodelist_false return getattr(node, "body", getattr(node, "nodes", []))
context.update(jingo.register.env.globals) context.update(jingo.register.env.filters) key = get_offline_hexdigest( Template.from_code(jingo.register.env, compiled_node, {}).render(context)) try: context['compress_forced'] = True compiled_node = env.compile(jinja2.nodes.Template([node])) result = Template.from_code(env, compiled_node, {}).render(context) except Exception, e: raise CommandError("An error occured during rendering %s: " "%s" % (template.template_name, e)) offline_manifest[key] = result context.pop() results.append(result) count += 1 write_offline_manifest(offline_manifest) log.write("done\nCompressed %d block(s) from %d template(s).\n" % (count, len(compressor_nodes))) return count, results def get_nodelist(self, node): if (isinstance(node, IfNode) and hasattr(node, 'nodelist_true') and hasattr(node, 'nodelist_false')): return node.nodelist_true + node.nodelist_false return getattr(node, "body", getattr(node, "nodes", []))