mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
menu can add base href automatically
This commit is contained in:
parent
0801f05450
commit
abbdae5691
10
menu.py
10
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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user