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