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