--- a/lib/page.py Sat Feb 07 01:33:30 2009 +0200
+++ b/lib/page.py Sat Feb 07 02:12:32 2009 +0200
@@ -67,6 +67,29 @@
return dict((c.name, c) for c in self.children).get(name)
+ def get_ancestry (self) :
+ """
+ Returns a list of this page's parents and the page itself, but not root
+ """
+
+ # collect in reverse order
+ ancestry = []
+
+ # starting from self
+ item = self
+
+ # add all items, but not root
+ while item and item.parent :
+ ancestry.append(item)
+
+ item = item.parent
+
+ # reverse
+ ancestry.reverse()
+
+ # done
+ return ancestry
+
@property
def url (self) :
"""
@@ -76,26 +99,13 @@
# cached?
if self._url :
return self._url
+
+ segments = [item.name for item in self.get_ancestry()]
- # collect URL segments in reverse order
- segments = []
-
# add empty segment if dir
if self.children :
segments.append('')
- # iterate over ancestry
- item = self
-
- # add all parent names, but not root's
- while item and item.parent :
- segments.append(item.name)
-
- item = item.parent
-
- # reverse segments
- segments.reverse()
-
# join
url = '/'.join(segments)