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
24 return val.validate_get(cls, name, id)
26 def validate_set(id, data):
27 return val.validate_set(cls, name, id, data)
29 def validate_new(data):
30 return val.validate_new(cls, name, data)
34 class CorreccionForm(W.TableForm):
35 class Fields(W.WidgetsList):
36 linstancia = W.Label(label=_(u'Instancia de Entrega'))
37 lentregador = W.Label(label=_(u'Entregador'))
38 lentrega = W.Label(label=_(u'Entrega'))
39 lcorrector = W.Label(label=_(u'Corrector'))
40 nota = W.TextField(label=_(u'Nota'), validator=V.Number(not_empty=False, strip=True))
41 observaciones = W.TextArea(label=_(u'Observaciones'), validator=V.UnicodeString(not_empty=False, strip=True))
43 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_instancia');")]
45 form = CorreccionForm()
49 class CorreccionController(controllers.Controller, identity.SecureResource):
50 """Basic model admin interface"""
51 require = identity.has_permission('admin')
54 def default(self, tg_errors=None):
55 """handle non exist urls"""
56 raise redirect('list')
60 raise redirect('list')
62 @expose(template='kid:%s.templates.list' % __name__)
65 """List records in model"""
67 return dict(records=r, name=name, namepl=namepl)
69 @expose(template='kid:%s.templates.edit' % __name__)
70 def edit(self, id, **kw):
71 """Edit record in model"""
73 r.linstancia = r.instancia.shortrepr()
74 r.lentregador = r.entregador.shortrepr()
75 r.lentrega = r.entrega.shortrepr()
76 r.lcorrector = r.corrector.shortrepr()
77 return dict(name=name, namepl=namepl, record=r, form=form)
82 def update(self, id, **kw):
83 """Save or create record to model"""
84 r = Correccion.get(id)
86 r.observaciones = kw['observaciones']
87 flash(_(u'El %s fue actualizado.') % name)
88 raise redirect('../list')
90 @expose(template='kid:%s.templates.show' % __name__)
91 def show(self,id, **kw):
92 """Show record in model"""
94 if r.observaciones is None:
97 r.obs = publish_parts(r.observaciones, writer_name='html')['html_body']
98 return dict(name=name, namepl=namepl, record=r)