1 from django.contrib import admin
2 from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin, EntityAdmin
3 from philo.models import Node
4 from philo.contrib.shipherd.models import NavigationItem, Navigation
7 NAVIGATION_RAW_ID_FIELDS = ('navigation', 'parent', 'target_node')
10 class NavigationItemInline(admin.StackedInline):
11 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
12 model = NavigationItem
14 sortable_field_name = 'order'
15 related_lookup_fields = {'fk': raw_id_fields}
18 class NavigationItemChildInline(NavigationItemInline):
19 verbose_name = "child"
20 verbose_name_plural = "children"
23 'fields': ('text', 'parent')
26 'fields': ('target_node', 'url_or_subpath',)
29 'fields': ('reversing_parameters', 'order'),
30 'classes': COLLAPSE_CLASSES
35 class NavigationNavigationItemInline(NavigationItemInline):
38 'fields': ('text', 'navigation')
41 'fields': ('target_node', 'url_or_subpath',)
44 'fields': ('reversing_parameters', 'order'),
45 'classes': COLLAPSE_CLASSES
50 class NodeNavigationItemInline(NavigationItemInline):
51 verbose_name_plural = 'targeting navigation'
57 'fields': ('target_node', 'url_or_subpath',)
60 'fields': ('reversing_parameters', 'order'),
61 'classes': COLLAPSE_CLASSES
64 'fields': ('parent', 'navigation')
69 class NodeNavigationInline(admin.TabularInline):
74 NodeAdmin.inlines = [NodeNavigationInline, NodeNavigationItemInline] + NodeAdmin.inlines
77 class NavigationItemAdmin(TreeEntityAdmin):
78 list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
81 'fields': ('text', 'navigation',)
84 'fields': ('target_node', 'url_or_subpath',)
87 'fields': ('reversing_parameters',),
88 'classes': COLLAPSE_CLASSES
91 'fields': ('parent', 'order'),
92 'classes': COLLAPSE_CLASSES
95 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
96 related_lookup_fields = {'fk': raw_id_fields}
97 inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines
100 class NavigationAdmin(EntityAdmin):
101 inlines = [NavigationNavigationItemInline]
102 raw_id_fields = ['node']
103 related_lookup_fields = {'fk': raw_id_fields}
106 admin.site.unregister(Node)
107 admin.site.register(Node, NodeAdmin)
108 admin.site.register(Navigation, NavigationAdmin)
109 admin.site.register(NavigationItem, NavigationItemAdmin)