From e10a6144b092d89e1410b240d7380d48a646ffc3 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Fri, 14 Jan 2011 10:08:12 -0500 Subject: [PATCH] Minor correction to Navigation.is_active() --- contrib/shipherd/models.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/contrib/shipherd/models.py b/contrib/shipherd/models.py index 8be03e2..2577245 100644 --- a/contrib/shipherd/models.py +++ b/contrib/shipherd/models.py @@ -203,14 +203,15 @@ class Navigation(TreeEntity): # match. return True - ancestors = node.get_ancestors(ascending=True, include_self=True).annotate(num_navigation=models.Count("hosted_navigation")).filter(num_navigation__gt=0) - if ancestors: - # If the target node is an ancestor of the requested node, this is - # active - unless the target node is the `home` node for this set of - # navigation or this navigation points to some other url. - host_node = ancestors[0] - if self.target_node.is_ancestor_of(node) and self.target_node != host_node and not self.url_or_subpath: - return True + if self.target_node: + ancestors = node.get_ancestors(ascending=True, include_self=True).annotate(num_navigation=models.Count("hosted_navigation")).filter(num_navigation__gt=0) + if ancestors: + # If the target node is an ancestor of the requested node, this is + # active - unless the target node is the `home` node for this set of + # navigation or this navigation points to some other url. + host_node = ancestors[0] + if self.target_node.is_ancestor_of(node) and self.target_node != host_node and not self.url_or_subpath: + return True # Always fall back to whether the node has active children. return self.has_active_children(request) -- 2.20.1