From: Stephen Burrows Date: Thu, 21 Oct 2010 21:41:19 +0000 (-0400) Subject: Bugfix: corrects erratic TreeModel get_path behavior. Was returning an extra slash... X-Git-Tag: philo-0.9~27^2~2^2 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/754fdcbe9c16f8b5b59c548e16ff128efbf74653?ds=sidebyside;hp=ace621afe8c9c2e835001bac819302cbdeb5e2df Bugfix: corrects erratic TreeModel get_path behavior. Was returning an extra slash at the end of paths with a given root. --- 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):