class NodeListRenderer
from yak.tags import NodeListRenderer
Helper Node to wrap a NodeList with a Node. Its role is to make syntax uniform. It is used to make a NodeList renderable as a single Node. It also keeps track of the parent tag uuid if available
Ancestors (MRO)
- builtins.object
- django.template.base.Node
- yak.tags.NodeListRenderer
| Attribute | Type | Defined in |
|---|---|---|
__dict__ |
getset_descriptor
|
django.template.base.Node |
__weakref__ |
getset_descriptor
|
django.template.base.Node |
| Attribute | Value | Defined in |
|---|---|---|
child_nodelists |
('nodelist',) |
django.template.base.Node |
must_be_first |
False |
django.template.base.Node |
token |
None |
django.template.base.Node |
def __init__(self, nodelist, uuid=None)
yak.tags.NodeListRenderer
Initialize self. See help(type(self)) for accurate signature.
def __init__(self, nodelist, uuid=None):
self.nodelist = nodelist
self.parent_uuid = uuid
def get_nodes_by_type(self, nodetype)
django.template.base.Node
Return a list of all nodes (within this node and its nodelist) of the given type
def get_nodes_by_type(self, nodetype):
"""
Return a list of all nodes (within this node and its nodelist)
of the given type
"""
nodes = []
if isinstance(self, nodetype):
nodes.append(self)
for attr in self.child_nodelists:
nodelist = getattr(self, attr, None)
if nodelist:
nodes.extend(nodelist.get_nodes_by_type(nodetype))
return nodes
def render(self, context)
yak.tags.NodeListRenderer
yak.tags.NodeListRenderer
Return the node rendered as a string.
def render(self, context):
# replace _parent_uuid in context and keep track of the previous one
if '_parent_uuid' in context:
prev_uuid = context['_parent_uuid']
else:
prev_uuid = None
context['_parent_uuid'] = self.parent_uuid
rv = self.nodelist.render(context)
# reset _parent_uuid to its previous value
if prev_uuid:
context['_parent_uuid'] = prev_uuid
else:
del context['_parent_uuid']
return rv
django.template.base.Node
Return the node rendered as a string.
def render(self, context):
"""
Return the node rendered as a string.
"""
pass
def render_annotated(self, context)
django.template.base.Node
Render the node. If debug is True and an exception occurs during rendering, the exception is annotated with contextual line information where it occurred in the template. For internal usage this method is preferred over using the render method directly.
def render_annotated(self, context):
"""
Render the node. If debug is True and an exception occurs during
rendering, the exception is annotated with contextual line information
where it occurred in the template. For internal usage this method is
preferred over using the render method directly.
"""
try:
return self.render(context)
except Exception as e:
if context.template.engine.debug:
# Store the actual node that caused the exception.
if not hasattr(e, "_culprit_node"):
e._culprit_node = self
if (
not hasattr(e, "template_debug")
and context.render_context.template.origin == e._culprit_node.origin
):
e.template_debug = (
context.render_context.template.get_exception_info(
e,
e._culprit_node.token,
)
)
raise