from turbogears import url
-from turbogears import controllers
+from turbogears.controllers import Controller
+from turbogears import identity
class Menu:
- def __init__(self, controller):
- # Armo la lista de subcontrollers
- self.items = []
- for i in controller.__dict__:
- if isinstance(getattr(controller, i),controllers.Controller):
- self.items.append(i)
+ def __init__(self, base):
+ self.base = base
+ self.items = filter(lambda i: isinstance(getattr(base, i), Controller), base.__dict__)
self.items.sort()
+ def _check(self, c):
+ return c.require.eval_with_object(identity.current)
+
def __repr__(self):
- t = """
+ option = u"""<option value="%s">%s</option>" """
+ template = """
<div id="navbar">
Ir a :
<select OnChange="window.location=this.options[this.selectedIndex].value;">
</select>
</div>
"""
- s = ''
+ s = option % ('', '-----')
for i in self.items:
- s = s + u"""<option value="%s">%s</option>" """ % (url('/' + i), i.capitalize().replace('_', ' '))
- return t % s
+ if self._check(getattr(self.base, i)):
+ s += option % (url('/' + i), i.capitalize().replace('_', ' '))
+ return template % s