Merged cowell back into core.
[philo.git] / contrib / shipherd / admin.py
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
5
6
7 NAVIGATION_RAW_ID_FIELDS = ('navigation', 'parent', 'target_node')
8
9
10 class NavigationItemInline(admin.StackedInline):
11         raw_id_fields = NAVIGATION_RAW_ID_FIELDS
12         model = NavigationItem
13         extra = 1
14         sortable_field_name = 'order'
15
16
17 class NavigationItemChildInline(NavigationItemInline):
18         verbose_name = "child"
19         verbose_name_plural = "children"
20         fieldsets = (
21                 (None, {
22                         'fields': ('text', 'parent')
23                 }),
24                 ('Target', {
25                         'fields': ('target_node', 'url_or_subpath',)
26                 }),
27                 ('Advanced', {
28                         'fields': ('reversing_parameters', 'order'),
29                         'classes': COLLAPSE_CLASSES
30                 })
31         )
32
33
34 class NavigationNavigationItemInline(NavigationItemInline):
35         fieldsets = (
36                 (None, {
37                         'fields': ('text', 'navigation')
38                 }),
39                 ('Target', {
40                         'fields': ('target_node', 'url_or_subpath',)
41                 }),
42                 ('Advanced', {
43                         'fields': ('reversing_parameters', 'order'),
44                         'classes': COLLAPSE_CLASSES
45                 })
46         )
47
48
49 class NodeNavigationItemInline(NavigationItemInline):
50         verbose_name_plural = 'targeting navigation'
51         fieldsets = (
52                 (None, {
53                         'fields': ('text',)
54                 }),
55                 ('Target', {
56                         'fields': ('target_node', 'url_or_subpath',)
57                 }),
58                 ('Advanced', {
59                         'fields': ('reversing_parameters', 'order'),
60                         'classes': COLLAPSE_CLASSES
61                 }),
62                 ('Expert', {
63                         'fields': ('parent', 'navigation')
64                 }),
65         )
66
67
68 class NodeNavigationInline(admin.TabularInline):
69         model = Navigation
70         extra = 1
71
72
73 NodeAdmin.inlines = [NodeNavigationInline, NodeNavigationItemInline] + NodeAdmin.inlines
74
75
76 class NavigationItemAdmin(TreeEntityAdmin):
77         list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
78         fieldsets = (
79                 (None, {
80                         'fields': ('text', 'navigation',)
81                 }),
82                 ('Target', {
83                         'fields': ('target_node', 'url_or_subpath',)
84                 }),
85                 ('Advanced', {
86                         'fields': ('reversing_parameters',),
87                         'classes': COLLAPSE_CLASSES
88                 }),
89                 ('Expert', {
90                         'fields': ('parent', 'order'),
91                         'classes': COLLAPSE_CLASSES
92                 })
93         )
94         raw_id_fields = NAVIGATION_RAW_ID_FIELDS
95         inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines
96
97
98 class NavigationAdmin(EntityAdmin):
99         inlines = [NavigationNavigationItemInline]
100         raw_id_fields = ['node']
101
102
103 admin.site.unregister(Node)
104 admin.site.register(Node, NodeAdmin)
105 admin.site.register(Navigation, NavigationAdmin)
106 admin.site.register(NavigationItem, NavigationItemAdmin)