Removed julian/tests.py and julian/views.py. Switched Location handling from a settin...
[philo.git] / contrib / shipherd / admin.py
index a54d0f1..93d21e5 100644 (file)
@@ -1,61 +1,90 @@
 from django.contrib import admin
-from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin
+from philo.admin import TreeEntityAdmin, COLLAPSE_CLASSES, NodeAdmin, EntityAdmin
 from philo.models import Node
-from philo.contrib.shipherd.models import Navigation
+from philo.contrib.shipherd.models import NavigationItem, Navigation
 
 
-NAVIGATION_RAW_ID_FIELDS = ('hosting_node', 'parent', 'target_node')
+NAVIGATION_RAW_ID_FIELDS = ('navigation', 'parent', 'target_node')
 
 
-class NavigationInline(admin.StackedInline):
+class NavigationItemInline(admin.StackedInline):
+       raw_id_fields = NAVIGATION_RAW_ID_FIELDS
+       model = NavigationItem
+       extra = 1
+       sortable_field_name = 'order'
+       related_lookup_fields = {'fk': raw_id_fields}
+
+
+class NavigationItemChildInline(NavigationItemInline):
+       verbose_name = "child"
+       verbose_name_plural = "children"
        fieldsets = (
                (None, {
-                       'fields': ('text',)
+                       'fields': ('text', 'parent')
                }),
                ('Target', {
                        'fields': ('target_node', 'url_or_subpath',)
                }),
                ('Advanced', {
-                       'fields': ('reversing_parameters', 'order', 'depth'),
+                       'fields': ('reversing_parameters', 'order'),
                        'classes': COLLAPSE_CLASSES
+               })
+       )
+
+
+class NavigationNavigationItemInline(NavigationItemInline):
+       fieldsets = (
+               (None, {
+                       'fields': ('text', 'navigation')
                }),
-               ('Expert', {
-                       'fields': ('hosting_node', 'parent'),
+               ('Target', {
+                       'fields': ('target_node', 'url_or_subpath',)
+               }),
+               ('Advanced', {
+                       'fields': ('reversing_parameters', 'order'),
                        'classes': COLLAPSE_CLASSES
                })
        )
-       raw_id_fields = NAVIGATION_RAW_ID_FIELDS
-       model = Navigation
-       extra = 1
-       sortable_field_name = 'order'
 
 
-class NavigationNavigationInline(NavigationInline):
-       verbose_name = "child"
-       verbose_name_plural = "children"
+class NodeNavigationItemInline(NavigationItemInline):
+       verbose_name_plural = 'targeting navigation'
+       fieldsets = (
+               (None, {
+                       'fields': ('text',)
+               }),
+               ('Target', {
+                       'fields': ('target_node', 'url_or_subpath',)
+               }),
+               ('Advanced', {
+                       'fields': ('reversing_parameters', 'order'),
+                       'classes': COLLAPSE_CLASSES
+               }),
+               ('Expert', {
+                       'fields': ('parent', 'navigation')
+               }),
+       )
 
 
-class NodeHostedNavigationInline(NavigationInline):
-       verbose_name_plural = 'hosted navigation'
-       fk_name = 'hosting_node'
+class NodeNavigationInline(admin.TabularInline):
+       model = Navigation
+       extra = 1
 
 
-class NodeTargetingNavigationInline(NavigationInline):
-       verbose_name_plural = 'targeting navigation'
-       fk_name = 'target_node'
+NodeAdmin.inlines = [NodeNavigationInline, NodeNavigationItemInline] + NodeAdmin.inlines
 
 
-class NavigationAdmin(TreeEntityAdmin):
+class NavigationItemAdmin(TreeEntityAdmin):
        list_display = ('__unicode__', 'target_node', 'url_or_subpath', 'reversing_parameters')
        fieldsets = (
                (None, {
-                       'fields': ('text', 'hosting_node',)
+                       'fields': ('text', 'navigation',)
                }),
                ('Target', {
                        'fields': ('target_node', 'url_or_subpath',)
                }),
                ('Advanced', {
-                       'fields': ('reversing_parameters', 'depth'),
+                       'fields': ('reversing_parameters',),
                        'classes': COLLAPSE_CLASSES
                }),
                ('Expert', {
@@ -64,12 +93,17 @@ class NavigationAdmin(TreeEntityAdmin):
                })
        )
        raw_id_fields = NAVIGATION_RAW_ID_FIELDS
-       inlines = [NavigationNavigationInline] + TreeEntityAdmin.inlines
+       related_lookup_fields = {'fk': raw_id_fields}
+       inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines
 
 
-NodeAdmin.inlines = [NodeHostedNavigationInline, NodeTargetingNavigationInline] + NodeAdmin.inlines
+class NavigationAdmin(EntityAdmin):
+       inlines = [NavigationNavigationItemInline]
+       raw_id_fields = ['node']
+       related_lookup_fields = {'fk': raw_id_fields}
 
 
 admin.site.unregister(Node)
 admin.site.register(Node, NodeAdmin)
-admin.site.register(Navigation, NavigationAdmin)
\ No newline at end of file
+admin.site.register(Navigation, NavigationAdmin)
+admin.site.register(NavigationItem, NavigationItemAdmin)
\ No newline at end of file