Bugfix: corrects erratic TreeModel get_path behavior. Was returning an extra slash...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 21 Oct 2010 21:41:19 +0000 (17:41 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Thu, 21 Oct 2010 21:41:19 +0000 (17:41 -0400)
models/base.py

index 05074c3..6f881a8 100644 (file)
@@ -307,22 +307,15 @@ class TreeModel(models.Model):
                return False
        
        def get_path(self, root=None, pathsep='/', field='slug'):
-               if root is not None:
-                       if not self.has_ancestor(root):
-                               raise AncestorDoesNotExist(root)
-                       path = ''
-                       parent = self
-                       while parent and parent != root:
-                               path = getattr(parent, field, '?') + pathsep + path
-                               parent = parent.parent
-                       return path
-               else:
-                       path = getattr(self, field, '?')
-                       parent = self.parent
-                       while parent and parent != root:
-                               path = getattr(parent, field, '?') + pathsep + path
-                               parent = parent.parent
-                       return path
+               if root is not None and not self.has_ancestor(root):
+                       raise AncestorDoesNotExist(root)
+               
+               path = getattr(self, field, '?')
+               parent = self.parent
+               while parent and parent != root:
+                       path = getattr(parent, field, '?') + pathsep + path
+                       parent = parent.parent
+               return path
        path = property(get_path)
        
        def __unicode__(self):