refactor: fix slot context behavior (#445)

This commit is contained in:
Juro Oravec 2024-04-23 21:35:45 +02:00 committed by GitHub
parent f3d6337ecc
commit 3ad0dd8677
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 287 additions and 80 deletions

View file

@ -1,6 +1,7 @@
from typing import List
from unittest.mock import Mock
from django.template import Context
from django.template import Context, Node
from django.template.response import TemplateResponse
from django.test import SimpleTestCase
@ -32,3 +33,22 @@ def create_and_process_template_response(template, context=None, use_middleware=
else:
response.render()
return response.content.decode("utf-8")
def print_nodes(nodes: List[Node], indent=0) -> None:
"""
Render a Nodelist, inlining child nodes with extra on separate lines and with
extra indentation.
"""
for node in nodes:
child_nodes: List[Node] = []
for attr in node.child_nodelists:
attr_child_nodes = getattr(node, attr, None) or []
if attr_child_nodes:
child_nodes.extend(attr_child_nodes)
repr = str(node)
repr = "\n".join([(" " * 4 * indent) + line for line in repr.split("\n")])
print(repr)
if child_nodes:
print_nodes(child_nodes, indent=indent + 1)