]> git.llucax.com Git - software/sercom.git/blob - sercom/menu.py
965e91175b99a7280f3abc886032f3a3b8e054fe
[software/sercom.git] / sercom / menu.py
1
2 from turbogears import url
3 from turbogears.controllers import Controller
4
5 class Menu:
6     def __init__(self, base):
7         # Armo la lista de subcontrollers
8         self.items = filter(lambda i: isinstance(getattr(base, i), Controller), base.__dict__)
9         self.items.sort()
10
11     def __repr__(self):
12         option = u"""<option value="%s">%s</option>" """
13         template = """
14         <div id="navbar">
15                         Ir a :
16                         <select OnChange="window.location=this.options[this.selectedIndex].value;">
17                                 %s
18                         </select>
19                 </div>
20         """
21         s = ''
22         for i in self.items:
23             s += option % (url('/' + i), i.capitalize().replace('_', ' '))
24         return template % s
25