From 26c548c5fe8c7cc7227b5f38cd27e0278442dd76 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Fri, 14 Jan 2011 12:02:03 -0500 Subject: [PATCH] Split shipherd NodeNavigationInline into inlines for hosted/targeting inlines. Added NodeAdmin reregistration to bring the new inlines into play. Added navigation_host filter. --- contrib/shipherd/admin.py | 15 ++++++++++++--- contrib/shipherd/models.py | 8 ++++---- contrib/shipherd/templatetags/shipherd.py | 8 ++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/contrib/shipherd/admin.py b/contrib/shipherd/admin.py index 606971d..a54d0f1 100644 --- a/contrib/shipherd/admin.py +++ b/contrib/shipherd/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin +from philo.models import Node from philo.contrib.shipherd.models import Navigation @@ -34,8 +35,14 @@ class NavigationNavigationInline(NavigationInline): verbose_name_plural = "children" -class NodeNavigationInline(NavigationInline): - verbose_name_plural = 'navigation' +class NodeHostedNavigationInline(NavigationInline): + verbose_name_plural = 'hosted navigation' + fk_name = 'hosting_node' + + +class NodeTargetingNavigationInline(NavigationInline): + verbose_name_plural = 'targeting navigation' + fk_name = 'target_node' class NavigationAdmin(TreeEntityAdmin): @@ -60,7 +67,9 @@ class NavigationAdmin(TreeEntityAdmin): inlines = [NavigationNavigationInline] + TreeEntityAdmin.inlines -NodeAdmin.inlines = [NodeNavigationInline] + NodeAdmin.inlines +NodeAdmin.inlines = [NodeHostedNavigationInline, NodeTargetingNavigationInline] + NodeAdmin.inlines +admin.site.unregister(Node) +admin.site.register(Node, NodeAdmin) admin.site.register(Navigation, NavigationAdmin) \ No newline at end of file diff --git a/contrib/shipherd/models.py b/contrib/shipherd/models.py index 2577245..0643c3e 100644 --- a/contrib/shipherd/models.py +++ b/contrib/shipherd/models.py @@ -71,11 +71,11 @@ class NavigationManager(TreeManager): return hosted_navigation def _add_to_cache(self, using, node, qs=None): - if node.pk is None: - return - if qs is None: - roots = node.hosted_navigation.select_related('target_node') + try: + roots = node.hosted_navigation.select_related('target_node') + except AttributeError: + roots = [] qs = self.none() for root in roots: diff --git a/contrib/shipherd/templatetags/shipherd.py b/contrib/shipherd/templatetags/shipherd.py index db15d46..019d240 100644 --- a/contrib/shipherd/templatetags/shipherd.py +++ b/contrib/shipherd/templatetags/shipherd.py @@ -87,6 +87,14 @@ def has_navigation(node): return bool(Navigation.objects.closest_navigation(node).count()) +@register.filter +def navigation_host(node): + try: + return Navigation.objects.closest_navigation(node)[0].hosting_node + except: + return node + + @register.filter def targeting_navigation(node): return Navigation.objects.closest_navigation(node).filter(target_node=node).order_by('level', 'lft') \ No newline at end of file -- 2.20.1