from django.core.urlresolvers import reverse
[docs]class Item:
def __init__(self, name, label='', icon='', route_name='', active_regex='^$', order=0):
self.name = name
self.label = label
self.icon = icon
self.route_name = route_name
self.active_regex = active_regex
self.order = order
self.depth = 1
self.children = list()
[docs] def add(self, item):
"""Add entry as child to the menuitem"""
idx = 0
for child in self.children:
if item.order < child.order:
break
idx += 1
self.children = self.children[:idx] + [item] + self.children[idx:]
[docs] def child_by_name(self, name):
"""Find child by name"""
for child in self.children:
if child.name == name:
return child
return None
@property
def url(self):
try:
return reverse(self.route_name)
except Exception:
return '#'
def __str__(self):
string = self.name + ' childs:\n'
for child in self.children:
string += str(child) + '\t'
return string