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 Practica'), 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 class AlumnoInscriptoFiltros(W.TableForm):
48 class Fields(W.WidgetsList):
49 cursoID = W.SingleSelectField(label=_(u'Curso'), options = get_cursos, validator = V.Int(not_empty=True))
52 filtro = AlumnoInscriptoFiltros()
53 form = AlumnoInscriptoForm()
57 class AlumnoInscriptoController(controllers.Controller, identity.SecureResource):
58 """Basic model admin interface"""
59 require = identity.has_permission('admin')
62 def default(self, tg_errors=None):
63 """handle non exist urls"""
64 raise redirect('list')
68 raise redirect('list')
70 @expose(template='kid:%s.templates.list' % __name__)
72 def list(self, cursoID = 0):
73 """List records in model"""
74 vfilter = dict(cursoID = cursoID)
78 r = cls.select(cls.q.cursoID == cursoID)
79 return dict(records=r, name=name, namepl=namepl, form=filtro, vfilter=vfilter)
81 @expose(template='kid:%s.templates.notas' % __name__)
82 def notas(self, id, **kw):
83 """Edit record in model"""
85 return dict(name=name, namepl=namepl, record=r, form=form)
90 def update(self, id, **kw):
91 """Save or create record to model"""
92 r = validate_set(id, kw)
93 flash(_(u'El %s fue actualizado.') % name)
94 raise redirect('../list')
96 @expose(template='kid:%s.templates.show' % __name__)
97 def show(self,id, **kw):
98 """Show record in model"""
100 return dict(name=name, namepl=namepl, record=r)