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 Correccion, Curso, Ejercicio, InstanciaDeEntrega
14 from sqlobject import *
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 CorreccionForm(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=False, 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 CorreccionFiltros(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 = CorreccionFiltros()
56 form = CorreccionForm()
60 class CorreccionController(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)
79 r = cls.selectBy(corrector=identity.current.user)
83 cls.q.correctorID == identity.current.user.id,
84 Ejercicio.q.id == InstanciaDeEntrega.q.ejercicioID,
85 InstanciaDeEntrega.q.id == Correccion.q.instanciaID,
86 Ejercicio.q.cursoID == cursoID
89 return dict(records=r, name=name, namepl=namepl, form=filtro, vfilter=vfilter)
91 @expose(template='kid:%s.templates.edit' % __name__)
92 def edit(self, id, **kw):
93 """Edit record in model"""
95 r.linstancia = r.instancia.shortrepr()
96 r.lentregador = r.entregador.shortrepr()
97 r.lentrega = r.entrega.shortrepr()
98 r.lcorrector = r.corrector.shortrepr()
99 return dict(name=name, namepl=namepl, record=r, form=form)
104 def update(self, id, **kw):
105 """Save or create record to model"""
106 from sqlobject import DateTimeCol
107 r = Correccion.get(id)
109 r.observaciones = kw['observaciones']
110 r.corregido = DateTimeCol.now()
111 flash(_(u'El %s fue actualizado.') % name)
112 raise redirect('../list')
114 @expose(template='kid:%s.templates.show' % __name__)
115 def show(self,id, **kw):
116 """Show record in model"""
118 if r.observaciones is None:
121 r.obs = publish_parts(r.observaciones, writer_name='html')['html_body']
122 return dict(name=name, namepl=namepl, record=r)
124 @expose(template='kid:%s.templates.entregas' % __name__)
126 def entregas(self, id):
128 return dict(records=r.entregas, correccion = id)