class RegroupNode

from django.template.defaulttags import RegroupNode


  

Ancestors (MRO)

  1. builtins.object
  2. django.template.base.Node
  3. django.template.defaulttags.RegroupNode
AttributeTypeDefined in
AttributeValueDefined in
def __init__(self, target, expression, var_name)
django.template.defaulttags.RegroupNode
Initialize self.  See help(type(self)) for accurate signature.
    def __init__(self, target, expression, var_name):
        self.target = target
        self.expression = expression
        self.var_name = var_name
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)
django.template.defaulttags.RegroupNode
django.template.defaulttags.RegroupNode
Return the node rendered as a string.
    def render(self, context):
        obj_list = self.target.resolve(context, ignore_failures=True)
        if obj_list is None:
            # target variable wasn't found in context; fail silently.
            context[self.var_name] = []
            return ""
        # List of dictionaries in the format:
        # {'grouper': 'key', 'list': [list of contents]}.
        context[self.var_name] = [
            GroupedResult(grouper=key, list=list(val))
            for key, val in groupby(
                obj_list, lambda obj: self.resolve_expression(obj, context)
            )
        ]
        return ""
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
def resolve_expression(self, obj, context)
django.template.defaulttags.RegroupNode
    def resolve_expression(self, obj, context):
        # This method is called for each object in self.target. See regroup()
        # for the reason why we temporarily put the object in the context.
        context[self.var_name] = obj
        return self.expression.resolve(context, ignore_failures=True)