1 from django.contrib import admin
3 from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin, EntityAdmin
4 from philo.models import Node
5 from philo.contrib.shipherd.models import NavigationItem, Navigation
8 NAVIGATION_RAW_ID_FIELDS = ('navigation', 'parent', 'target_node')
11 class NavigationItemInline(admin.StackedInline):
12 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
13 model = NavigationItem
15 sortable_field_name = 'order'
16 related_lookup_fields = {'fk': raw_id_fields}
19 class NavigationItemChildInline(NavigationItemInline):
20 verbose_name = "child"
21 verbose_name_plural = "children"
24 'fields': ('text', 'parent')
27 'fields': ('target_node', 'url_or_subpath',)
30 'fields': ('reversing_parameters', 'order'),
31 'classes': COLLAPSE_CLASSES
36 class NavigationNavigationItemInline(NavigationItemInline):
39 'fields': ('text', 'navigation')
42 'fields': ('target_node', 'url_or_subpath',)
45 'fields': ('reversing_parameters', 'order'),
46 'classes': COLLAPSE_CLASSES
51 class NodeNavigationItemInline(NavigationItemInline):
52 verbose_name_plural = 'targeting navigation'
58 'fields': ('target_node', 'url_or_subpath',)
61 'fields': ('reversing_parameters', 'order'),
62 'classes': COLLAPSE_CLASSES
65 'fields': ('parent', 'navigation')
70 class NodeNavigationInline(admin.TabularInline):
75 NodeAdmin.inlines = [NodeNavigationInline, NodeNavigationItemInline] + NodeAdmin.inlines
78 class NavigationItemAdmin(TreeEntityAdmin):
79 list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
82 'fields': ('text', 'navigation',)
85 'fields': ('target_node', 'url_or_subpath',)
88 'fields': ('reversing_parameters',),
89 'classes': COLLAPSE_CLASSES
92 'fields': ('parent', 'order'),
93 'classes': COLLAPSE_CLASSES
96 raw_id_fields = NAVIGATION_RAW_ID_FIELDS
97 related_lookup_fields = {'fk': raw_id_fields}
98 inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines
101 class NavigationAdmin(EntityAdmin):
102 inlines = [NavigationNavigationItemInline]
103 raw_id_fields = ['node']
104 related_lookup_fields = {'fk': raw_id_fields}
107 admin.site.unregister(Node)
108 admin.site.register(Node, NodeAdmin)
109 admin.site.register(Navigation, NavigationAdmin)
110 admin.site.register(NavigationItem, NavigationItemAdmin)