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 linstancia = W.Label(label=_(u'Instancia de Entrega'))
39 lentregador = W.Label(label=_(u'Entregador'))
40 lentrega = W.Label(label=_(u'Entrega'))
41 lcorrector = W.Label(label=_(u'Corrector'))
42 nota = W.TextField(label=_(u'Nota'), validator=V.Number(not_empty=True, strip=True))
43 observaciones = W.TextArea(label=_(u'Observaciones'), validator=V.UnicodeString(not_empty=False, strip=True))
45 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_instancia');")]
48 return [(0, u'---')] + [(fk1.id, fk1.shortrepr()) for fk1 in Curso.select()]
50 class AlumnoInscriptoFiltros(W.TableForm):
51 class Fields(W.WidgetsList):
52 cursoID = W.SingleSelectField(label=_(u'Curso'), options = get_cursos, validator = V.Int(not_empty=True))
55 filtro = AlumnoInscriptoFiltros()
56 form = AlumnoInscriptoForm()
60 class AlumnoInscriptoController(controllers.Controller, identity.SecureResource):
61 """Basic model admin interface"""
62 require = identity.has_permission('admin')
65 def default(self, tg_errors=None):
66 """handle non exist urls"""
67 raise redirect('list')
71 raise redirect('list')
73 @expose(template='kid:%s.templates.list' % __name__)
75 def list(self, cursoID = 0):
76 """List records in model"""
77 vfilter = dict(cursoID = cursoID)
81 r = cls.select(cls.q.cursoID == cursoID)
82 return dict(records=r, name=name, namepl=namepl, form=filtro, vfilter=vfilter)
84 @expose(template='kid:%s.templates.edit' % __name__)
85 def edit(self, id, **kw):
86 """Edit record in model"""
88 r.linstancia = r.instancia.shortrepr()
89 r.lentregador = r.entregador.shortrepr()
90 r.lentrega = r.entrega.shortrepr()
91 r.lcorrector = r.corrector.shortrepr()
92 return dict(name=name, namepl=namepl, record=r, form=form)
97 def update(self, id, **kw):
98 """Save or create record to model"""
99 from sqlobject import DateTimeCol
100 r = Correccion.get(id)
102 r.observaciones = kw['observaciones']
103 r.corregido = DateTimeCol.now()
104 flash(_(u'El %s fue actualizado.') % name)
105 raise redirect('../list')
107 @expose(template='kid:%s.templates.show' % __name__)
108 def show(self,id, **kw):
109 """Show record in model"""
111 if r.observaciones is None:
114 r.obs = publish_parts(r.observaciones, writer_name='html')['html_body']
115 return dict(name=name, namepl=namepl, record=r)
117 @expose(template='kid:%s.templates.entregas' % __name__)
119 def entregas(self, id):
121 return dict(records=r.entregas, correccion = id)