Added MPTTModelAdmin integration. Committed docstring changes for get_with_path.
authorStephen Burrows <stephen.r.burrows@gmail.com>
Mon, 15 Nov 2010 16:39:46 +0000 (11:39 -0500)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Mon, 15 Nov 2010 16:39:46 +0000 (11:39 -0500)
admin/base.py
admin/nodes.py
admin/pages.py
models/base.py

index 0413dde..0d35cf6 100644 (file)
@@ -7,6 +7,7 @@ from django.utils.html import escape
 from philo.models import Tag, Attribute
 from philo.forms import AttributeForm, AttributeInlineFormSet
 from philo.admin.widgets import TagFilteredSelectMultiple
 from philo.models import Tag, Attribute
 from philo.forms import AttributeForm, AttributeInlineFormSet
 from philo.admin.widgets import TagFilteredSelectMultiple
+from mptt.admin import MPTTModelAdmin
 
 
 COLLAPSE_CLASSES = ('collapse', 'collapse-closed', 'closed',)
 
 
 COLLAPSE_CLASSES = ('collapse', 'collapse-closed', 'closed',)
@@ -33,6 +34,14 @@ class EntityAdmin(admin.ModelAdmin):
        save_on_top = True
 
 
        save_on_top = True
 
 
+class TreeAdmin(MPTTModelAdmin):
+       pass
+
+
+class TreeEntityAdmin(TreeAdmin, EntityAdmin):
+       pass
+
+
 class TagAdmin(admin.ModelAdmin):
        list_display = ('name', 'slug')
        prepopulated_fields = {"slug": ("name",)}
 class TagAdmin(admin.ModelAdmin):
        list_display = ('name', 'slug')
        prepopulated_fields = {"slug": ("name",)}
index 093537e..45a3172 100644 (file)
@@ -1,9 +1,9 @@
 from django.contrib import admin
 from django.contrib import admin
-from philo.admin.base import EntityAdmin
+from philo.admin.base import EntityAdmin, TreeEntityAdmin
 from philo.models import Node, Redirect, File
 
 
 from philo.models import Node, Redirect, File
 
 
-class NodeAdmin(EntityAdmin):
+class NodeAdmin(TreeEntityAdmin):
        pass
 
 
        pass
 
 
index 15b06d9..caeee05 100644 (file)
@@ -1,7 +1,7 @@
 from django.conf import settings
 from django.contrib import admin
 from django import forms
 from django.conf import settings
 from django.contrib import admin
 from django import forms
-from philo.admin.base import COLLAPSE_CLASSES
+from philo.admin.base import COLLAPSE_CLASSES, TreeAdmin
 from philo.admin.nodes import ViewAdmin
 from philo.models.pages import Page, Template, Contentlet, ContentReference
 from philo.forms import ContentletInlineFormSet, ContentReferenceInlineFormSet, ContentletForm, ContentReferenceForm
 from philo.admin.nodes import ViewAdmin
 from philo.models.pages import Page, Template, Contentlet, ContentReference
 from philo.forms import ContentletInlineFormSet, ContentReferenceInlineFormSet, ContentletForm, ContentReferenceForm
@@ -48,7 +48,7 @@ class PageAdmin(ViewAdmin):
        inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
 
 
        inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
 
 
-class TemplateAdmin(admin.ModelAdmin):
+class TemplateAdmin(TreeAdmin):
        prepopulated_fields = {'slug': ('name',)}
        fieldsets = (
                (None, {
        prepopulated_fields = {'slug': ('name',)}
        fieldsets = (
                (None, {
index c2c12ad..ce74489 100644 (file)
@@ -282,10 +282,14 @@ class TreeManager(models.Manager):
        
        def get_with_path(self, path, root=None, absolute_result=True, pathsep='/', field='slug'):
                """
        
        def get_with_path(self, path, root=None, absolute_result=True, pathsep='/', field='slug'):
                """
-               Given a <pathsep>-separated path, fetch the matching model of this type. If the path
-               you're searching for is known to exist, it is always faster to use absolute_result=True.
-               Unless the path depth is over ~40, in which case the high cost of the absolute query
-               makes a binary search (i.e. non-absolute) faster.
+               Returns the object with the path, unless absolute_result is set to False, in which
+               case it returns a tuple containing the deepest object found along the path, and the
+               remainder of the path after that object as a string (or None if there is no remaining
+               path). Raises a DoesNotExist exception if no object is found with the given path.
+               
+               If the path you're searching for is known to exist, it is always faster to use
+               absolute_result=True - unless the path depth is over ~40, in which case the high cost
+               of the absolute query makes a binary search (i.e. non-absolute) faster.
                """
                # Note: SQLite allows max of 64 tables in one join. That means the binary search will
                # only work on paths with a max depth of 127 and the absolute fetch will only work
                """
                # Note: SQLite allows max of 64 tables in one join. That means the binary search will
                # only work on paths with a max depth of 127 and the absolute fetch will only work