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=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 CorreccionFiltros(W.TableForm):
51 class Fields(W.WidgetsList):
52 cursoID = W.SingleSelectField(label=_(u'Curso'), options = get_cursos, validator = V.Int(not_empty=True))
53 form_attrs={'class':"filter"}
56 filtro = CorreccionFiltros()
57 form = CorreccionForm()
61 class CorreccionController(controllers.Controller, identity.SecureResource):
62 """Basic model admin interface"""
63 require = identity.has_permission('admin')
66 def default(self, tg_errors=None):
67 """handle non exist urls"""
68 raise redirect('list')
72 raise redirect('list')
74 @expose(template='kid:%s.templates.list' % __name__)
76 def list(self, cursoID = 0):
77 """List records in model"""
78 vfilter = dict(cursoID = cursoID)
80 r = cls.selectBy(corrector=identity.current.user)
84 cls.q.correctorID == identity.current.user.id,
85 Ejercicio.q.id == InstanciaDeEntrega.q.ejercicioID,
86 InstanciaDeEntrega.q.id == Correccion.q.instanciaID,
87 Ejercicio.q.cursoID == cursoID
90 return dict(records=r, name=name, namepl=namepl, form=filtro, vfilter=vfilter)
92 @expose(template='kid:%s.templates.edit' % __name__)
93 def edit(self, id, **kw):
94 """Edit record in model"""
96 r.linstancia = r.instancia.shortrepr()
97 r.lentregador = r.entregador.shortrepr()
98 r.lentrega = r.entrega.shortrepr()
99 r.lcorrector = r.corrector.shortrepr()
100 return dict(name=name, namepl=namepl, record=r, form=form)
105 def update(self, id, **kw):
106 """Save or create record to model"""
107 from sqlobject import DateTimeCol
108 r = Correccion.get(id)
110 r.observaciones = kw['observaciones']
111 r.corregido = DateTimeCol.now()
112 flash(_(u'El %s fue actualizado.') % name)
113 raise redirect('../list')
115 @expose(template='kid:%s.templates.show' % __name__)
116 def show(self,id, **kw):
117 """Show record in model"""
119 if r.observaciones is None:
122 r.obs = publish_parts(r.observaciones, writer_name='html')['html_body']
123 return dict(name=name, namepl=namepl, record=r)
125 @expose(template='kid:%s.templates.entregas' % __name__)
127 def entregas(self, id):
129 return dict(records=r.entregas, correccion = id)