From ab7d1efef433b723e30a62773f3cf0bbbb35a407 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 1 Dec 2010 16:49:35 -0500 Subject: [PATCH] Corrected embed handling to ignore embedded instances which do not appear in the context. --- templatetags/embed.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templatetags/embed.py b/templatetags/embed.py index 901e163..e8c4cae 100644 --- a/templatetags/embed.py +++ b/templatetags/embed.py @@ -65,6 +65,9 @@ def get_embed_dict(embed_list, context): embeds = {} for e in embed_list: ct = e.get_content_type(context) + if ct is None: + # Then the embed doesn't exist for this context. + continue if ct not in embeds: embeds[ct] = [e] else: @@ -263,7 +266,10 @@ class InstanceEmbedNode(EmbedNode): return self.instance.resolve(context) def get_content_type(self, context): - return ContentType.objects.get_for_model(self.get_instance(context)) + instance = self.get_instance(context) + if instance is None: + return None + return ContentType.objects.get_for_model(instance) def get_embedded(self): -- 2.20.1