]> git.llucax.com Git - z.facultad/75.52/sercom.git/blob - sercom/menu.py
Controller de AlumnoInscripto basico.
[z.facultad/75.52/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         self.items = ['dashboard'] + self.items
12
13     def _check(self, c):
14         return c.require.eval_with_object(identity.current)
15
16     def __repr__(self):
17         option = u"""<option value="%s">%s</option>" """
18         template = """
19         <div id="navbar">
20                         Ir a :
21                         <select OnChange="window.location=this.options[this.selectedIndex].value;">
22                                 %s
23                         </select>
24                 </div>
25         """
26         s = option % ('', '-----')
27         for i in self.items:
28             if i == 'dashboard' or self._check(getattr(self.base, i)):
29                 s += option % (url('/' + i), i.capitalize().replace('_', ' '))
30         return template % s
31