1 # vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker :
5 from turbogears import controllers, expose, redirect
6 from turbogears import validate, flash, error_handler
7 from turbogears import validators as V
8 from turbogears import widgets as W
9 from turbogears import identity
10 from turbogears import paginate
11 from docutils.core import publish_parts
12 from sercom.subcontrollers import validate as val
13 from sercom.model import AlumnoInscripto, Correccion, Curso, Ejercicio, InstanciaDeEntrega
14 from sqlobject import *
20 name = 'alumno inscripto'
21 namepl = 'alumnos inscriptos'
26 return val.validate_get(cls, name, id)
28 def validate_set(id, data):
29 return val.validate_set(cls, name, id, data)
31 def validate_new(data):
32 return val.validate_new(cls, name, data)
36 class AlumnoInscriptoForm(W.TableForm):
37 class Fields(W.WidgetsList):
38 nota_practica = W.TextField(label=_(u'Nota Práctica'), validator=V.Number(not_empty=True, strip=True))
39 nota_final = W.TextField(label=_(u'Nota Final'), validator=V.Number(not_empty=True, strip=True))
40 nota_libreta = W.TextField(label=_(u'Nota Libreta'), validator=V.Number(not_empty=True, strip=True))
42 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nota_practica');")]
45 return [(0, u'---')] + [(fk1.id, fk1.shortrepr()) for fk1 in Curso.select()]
47 form = AlumnoInscriptoForm()
51 class AlumnoInscriptoController(controllers.Controller, identity.SecureResource):
52 """Basic model admin interface"""
53 require = identity.has_permission('admin')
56 def default(self, tg_errors=None):
57 """handle non exist urls"""
58 raise redirect('list')
62 raise redirect('list')
64 @expose(template='kid:%s.templates.list' % __name__)
66 def list(self, cursoID = 0):
67 """List records in model"""
68 cursoID = int(cursoID)
72 r = cls.select(cls.q.cursoID == cursoID)
73 curso = Curso.get(cursoID)
74 return dict(records=r, name=name, namepl=namepl, curso=curso)
76 @expose(template='kid:%s.templates.notas' % __name__)
77 def notas(self, id, cursoID, **kw):
78 """Edit record in model"""
79 cursoID = int(cursoID)
81 return dict(name=name, namepl=namepl, record=r, form=form, cursoid=cursoID)
86 def update(self, id, cursoID, **kw):
87 """Save or create record to model"""
88 cursoID = int(cursoID)
89 r = validate_set(id, kw)
90 flash(_(u'El %s fue actualizado.') % name)
91 raise redirect('../list/%d' % cursoID)
93 @expose(template='kid:%s.templates.show' % __name__)
94 def show(self,id, **kw):
95 """Show record in model"""
97 return dict(name=name, namepl=namepl, record=r)