from turbogears import url
+from turbogears import controllers
+
+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)
+ self.items.sort()
+
+ def __repr__(self):
+ t = """
+ <div id="navbar">
+ Ir a :
+ <select OnChange="window.location=this.options[this.selectedIndex].value;">
+ %s
+ </select>
+ </div>
+ """
+ s = ''
+ for i in self.items:
+ s = s + u"""<option value="%s" %s>%s</option>" """ % (url('/' + i), i.capitalize().replace('_', ' '))
+ return t % s
-menu = []
-menu.append({'name': 'Alumnos', 'url':url('/alumno')})
-menu.append({'name': 'Docentes', 'url':url('/docente')})
-menu.append({'name': 'Grupos', 'url':url('/grupo')})
-menu.append({'name': 'Enunciados', 'url':url('/enunciado')})
-menu.append({'name': 'Ejercicios', 'url':url('/ejercicio')})
-menu.append({'name': 'Casos de Prueba', 'url':url('/caso_de_prueba')})
-menu.append({'name': 'Cursos', 'url':url('/curso')})
<th>Operaciones</th>
</tr>
<tr py:for="record in records">
- <td><span py:replace="record.curso.shortrepr()">curso</span></td>
+ <td><a href="${tg.url('/curso/show/'+str(record.curso.id))}" py:content="record.curso.shortrepr()">curso</a></td>
<td><span py:replace="record.nombre">nombre</span></td>
<td><a py:if="record.responsable is not None" href="${tg.url('/alumno/show/'+str(record.responsable.alumno.id))}" py:content="record.responsable.alumno.shortrepr()"></a></td>
<td>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?python import sitetemplate ?>
-<?python from sercom.menu import menu ?>
+<?python
+ from sercom.menu import Menu
+ from sercom.controllers import Root
+ menu = Menu(Root)
+?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="sitetemplate">
<head py:match="item.tag=='{http://www.w3.org/1999/xhtml}head'" py:attrs="item.items()">
</div>
<div py:if="tg_flash" class="flash" py:content="tg_flash"></div>
- <div id="navbar">
- Ir a :
- <select OnChange="window.location=this.options[this.selectedIndex].value;">
- <option value="${tg.url('/')}">Inicio</option>
- <option py:for="i in menu" value="${tg.url(i['url'])}">
- ${i['name']}
- </option>
- </select>
- </div>
+ ${XML(str(menu))}
+
<div py:replace="[item.text]+item[:]"/>
<!-- End of main_content -->