From 754fdcbe9c16f8b5b59c548e16ff128efbf74653 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Thu, 21 Oct 2010 17:41:19 -0400 Subject: [PATCH] Bugfix: corrects erratic TreeModel get_path behavior. Was returning an extra slash at the end of paths with a given root. --- models/base.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/models/base.py b/models/base.py index 05074c3..6f881a8 100644 --- a/models/base.py +++ b/models/base.py @@ -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): -- 2.20.1