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 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 return dict(records=r, name=name, namepl=namepl, cursoid=cursoID)
75 @expose(template='kid:%s.templates.notas' % __name__)
76 def notas(self, id, cursoID, **kw):
77 """Edit record in model"""
78 cursoID = int(cursoID)
80 return dict(name=name, namepl=namepl, record=r, form=form, cursoid=cursoID)
85 def update(self, id, cursoID, **kw):
86 """Save or create record to model"""
87 cursoID = int(cursoID)
88 r = validate_set(id, kw)
89 flash(_(u'El %s fue actualizado.') % name)
90 raise redirect('../list/%d' % cursoID)
92 @expose(template='kid:%s.templates.show' % __name__)
93 def show(self,id,cursoID, **kw):
94 """Show record in model"""
95 cursoID = int(cursoID)
97 return dict(name=name, namepl=namepl, record=r, cursoid=cursoID)