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