mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-04 08:53:42 +00:00
Add a menu method to find menu items by URL
This commit is contained in:
parent
1ec92ee346
commit
4e318ff434
11
menu.py
11
menu.py
@ -29,6 +29,17 @@ class Menu(object):
|
||||
self.order = order
|
||||
self.items = []
|
||||
|
||||
def find(self, url, basehref=True):
|
||||
"""Return a menu item with given URL"""
|
||||
if basehref and url.startswith('/'):
|
||||
url = cfg.server_dir + url
|
||||
|
||||
for item in self.items:
|
||||
if item.url == url:
|
||||
return item
|
||||
|
||||
raise KeyError('Menu item not found')
|
||||
|
||||
def sort_items(self):
|
||||
"""Sort the items in self.items by order."""
|
||||
self.items = sorted(self.items, key=lambda x: x.order, reverse=False)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user