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