From 80fa50c87ed121896ddf1bdd993d5697bb5a56c3 Mon Sep 17 00:00:00 2001 From: melinath Date: Wed, 9 Jun 2010 17:46:48 -0400 Subject: [PATCH] Fixed a bug where the ContainerNode had a nodelist_empty=None, whereas nodelist_empty is expected to be an iterable by line 314 of models.py. Also added 'nodelist_main' to the manage.py line 314 list of subnodelist possibilities and added a child_nodelists attribute to ContainerNode for possible forward-compatibility. --- models.py | 2 +- templatetags/containers.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/models.py b/models.py index b1da9d0..dcb5d74 100644 --- a/models.py +++ b/models.py @@ -311,7 +311,7 @@ class Template(TreeModel): nodes = [] for node in nodelist: try: - for nodelist_name in ('nodelist', 'nodelist_loop', 'nodelist_empty', 'nodelist_true', 'nodelist_false'): + for nodelist_name in ('nodelist', 'nodelist_loop', 'nodelist_empty', 'nodelist_true', 'nodelist_false', 'nodelist_main'): if hasattr(node, nodelist_name): nodes.extend(nodelist_container_nodes(getattr(node, nodelist_name))) if isinstance(node, ContainerNode): diff --git a/templatetags/containers.py b/templatetags/containers.py index 45a9965..c04cb64 100644 --- a/templatetags/containers.py +++ b/templatetags/containers.py @@ -9,12 +9,22 @@ register = template.Library() class ContainerNode(template.Node): + child_nodelists = ('nodelist_main', 'nodelist_empty',) + def __init__(self, name, references=None, as_var=None, nodelist_main=None, nodelist_empty=None): self.name = name self.as_var = as_var self.references = references - self.nodelist_main = nodelist_main - self.nodelist_empty = nodelist_empty + + if nodelist_main is None: + self.nodelist_main = template.NodeList() + else: + self.nodelist_main = nodelist_main + + if nodelist_empty is None: + self.nodelist_empty = template.NodeList() + else: + self.nodelist_empty = nodelist_empty def render(self, context): content = settings.TEMPLATE_STRING_IF_INVALID @@ -22,6 +32,7 @@ class ContainerNode(template.Node): container_content = self.get_container_content(context['page']) if self.nodelist_main is None: + self.nodelist_main if container_content and self.as_var: context[self.as_var] = container_content return '' -- 2.20.1