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'
17 class NavigationItemChildInline(NavigationItemInline):
18 verbose_name = "child"
19 verbose_name_plural = "children"
22 'fields': ('text', 'parent')
25 'fields': ('target_node', 'url_or_subpath',)
28 'fields': ('reversing_parameters', 'order'),
29 'classes': COLLAPSE_CLASSES
34 class NavigationNavigationItemInline(NavigationItemInline):
37 'fields': ('text', 'navigation')
40 'fields': ('target_node', 'url_or_subpath',)
43 'fields': ('reversing_parameters', 'order'),
44 'classes': COLLAPSE_CLASSES
49 class NodeNavigationItemInline(NavigationItemInline):
50 verbose_name_plural = 'targeting navigation'
56 'fields': ('target_node', 'url_or_subpath',)
59 'fields': ('reversing_parameters', 'order'),
60 'classes': COLLAPSE_CLASSES
63 'fields': ('parent', 'navigation')
68 class NodeNavigationInline(admin.TabularInline):
73 NodeAdmin.inlines = [NodeNavigationInline, NodeNavigationItemInline] + NodeAdmin.inlines
76 class NavigationItemAdmin(TreeEntityAdmin):
77 list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
80 'fields': ('text', 'navigation',)
83 'fields': ('target_node', 'url_or_subpath',)
86 'fields': ('reversing_parameters',),
87 'classes': COLLAPSE_CLASSES
90 'fields': ('parent', 'order'),
91 'classes': COLLAPSE_CLASSES
94 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
95 inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines
98 class NavigationAdmin(EntityAdmin):
99 inlines = [NavigationNavigationItemInline]
100 raw_id_fields = ['node']
103 admin.site.unregister(Node)
104 admin.site.register(Node, NodeAdmin)
105 admin.site.register(Navigation, NavigationAdmin)
106 admin.site.register(NavigationItem, NavigationItemAdmin)