summaryrefslogtreecommitdiff
path: root/menu.py
diff options
context:
space:
mode:
authorJames Vasile <james@hackervisions.org>2011-12-20 21:30:21 -0500
committerJames Vasile <james@jamesvasile.com>2012-02-19 15:07:15 -0500
commitabbdae5691210eb7d261d7b014f627723ff9bcd1 (patch)
tree0b5d8f3a5ebfeb909ce7fdb557574c2044e6f9b5 /menu.py
parent0801f05450d3492a50adf1e7c3fde24a9780e163 (diff)
menu can add base href automatically
Diffstat (limited to 'menu.py')
-rw-r--r--menu.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/menu.py b/menu.py
index e0e376a..3e682e4 100644
--- a/menu.py
+++ b/menu.py
@@ -27,9 +27,15 @@ class Menu():
def sort_items(self):
"""Sort the items in self.items by order."""
self.items = sorted(self.items, key=lambda x: x.order, reverse=False)
- def add_item(self, label, url, order=50):
+ def add_item(self, label, url, order=50, basehref=True):
"""This method creates a menu item with the parameters, adds
- that menu item to this menu, and returns the item."""
+ that menu item to this menu, and returns the item.
+
+ If BASEHREF is true and url start with a slash, prepend the cfg.base_href to it"""
+
+ if basehref and url.startswith("/"):
+ url = cfg.base_href + url
+
item = Menu(label=label, url=url, order=order)
self.items.append(item)
self.sort_items()