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
14 from sercom.model import InstanciaDeEntrega, DocenteInscripto
15 from sqlobject import *
27 return val.validate_get(cls, name, id)
29 def validate_set(id, data):
30 return val.validate_set(cls, name, id, data)
32 def validate_new(data):
33 return val.validate_new(cls, name, data)
37 class CorreccionForm(W.TableForm):
38 class Fields(W.WidgetsList):
39 linstancia = W.Label(label=_(u'Instancia de Entrega'))
40 lentregador = W.Label(label=_(u'Entregador'))
41 lentrega = W.Label(label=_(u'Entrega'))
42 lcorrector = W.Label(label=_(u'Corrector'))
43 nota = W.TextField(label=_(u'Nota'), validator=V.Number(not_empty=True, strip=True))
44 observaciones = W.TextArea(label=_(u'Observaciones'), validator=V.UnicodeString(not_empty=False, strip=True))
46 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_instancia');")]
48 class CorreccionFiltros(W.TableForm):
49 class Fields(W.WidgetsList):
50 cursoID = W.SingleSelectField(label=_(u'Curso'), validator=V.Int(not_empty=True))
51 form_attrs={'class':"filter"}
54 filtro = CorreccionFiltros()
55 form = CorreccionForm()
59 class CorreccionController(controllers.Controller, identity.SecureResource):
60 """Basic model admin interface"""
61 require = identity.has_permission('admin')
64 def default(self, tg_errors=None):
65 """handle non exist urls"""
66 raise redirect('list')
70 raise redirect('list')
72 @expose(template='kid:%s.templates.list' % __name__)
73 @validate(validators=dict(cursoID=V.Int))
75 def list(self, cursoID=None):
76 """List records in model"""
77 vfilter = dict(cursoID=cursoID)
82 cls.q.correctorID == DocenteInscripto.pk.get(
83 cursoID=cursoID, docenteID=identity.current.user.id).id,
84 Ejercicio.q.id == InstanciaDeEntrega.q.ejercicioID,
85 InstanciaDeEntrega.q.id == Correccion.q.instanciaID,
86 Ejercicio.q.cursoID == cursoID
89 cursos = [(i.curso.id, i.curso.shortrepr())
90 for i in identity.current.user.inscripciones]
91 return dict(records=r, name=name, namepl=namepl, form=filtro,
92 vfilter=vfilter, options=dict(cursoID=cursos))
94 @expose(template='kid:%s.templates.edit' % __name__)
95 def edit(self, id, **kw):
96 """Edit record in model"""
98 r.linstancia = r.instancia.shortrepr()
99 r.lentregador = r.entregador.shortrepr()
100 r.lentrega = r.entrega.shortrepr()
101 r.lcorrector = r.corrector.shortrepr()
102 return dict(name=name, namepl=namepl, record=r, form=form)
107 def update(self, id, **kw):
108 """Save or create record to model"""
109 from sqlobject import DateTimeCol
110 r = Correccion.get(id)
112 r.observaciones = kw['observaciones']
113 r.corregido = DateTimeCol.now()
114 flash(_(u'El %s fue actualizado.') % name)
115 raise redirect('../list')
117 @expose(template='kid:%s.templates.show' % __name__)
118 def show(self,id, **kw):
119 """Show record in model"""
121 return dict(name=name, namepl=namepl, record=r)
123 @expose(template='kid:%s.templates.entregas' % __name__)
125 def entregas(self, id):
127 return dict(records=r.entregas, correccion = id)