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 TareaPrueba
14 from sqlobject import *
15 from comandos import ComandoPruebaController
21 namepl = 'tareas prueba'
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 TareaPruebaForm(W.TableForm):
37 class Fields(W.WidgetsList):
38 nombre = W.TextField(label=_(u'Nombre'),validator=V.UnicodeString(min=3, max=30, strip=True))
39 descripcion = W.TextField(label=_(u'Descripcion'),
40 validator=V.UnicodeString(not_empty=False, max=255, strip=True))
42 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")]
44 form = TareaPruebaForm()
48 class TareaPruebaController(controllers.Controller, identity.SecureResource):
49 """Basic model admin interface"""
50 require = identity.has_permission('admin')
52 comandos = ComandoPruebaController()
55 def default(self, tg_errors=None):
56 """handle non exist urls"""
57 raise redirect('list')
61 raise redirect('list')
63 @expose(template='kid:%s.templates.list' % __name__)
66 """List records in model"""
68 return dict(records=r, name=name, namepl=namepl)
70 @expose(template='kid:%s.templates.new' % __name__)
72 """Create new records in model"""
73 return dict(name=name, namepl=namepl, form=form, values=kw)
78 def create(self, **kw):
79 """Save or create record to model"""
81 flash(_(u'Se creó un nuevo %s.') % name)
82 raise redirect('list')
84 @expose(template='kid:%s.templates.edit' % __name__)
85 def edit(self, id, **kw):
86 """Edit record in model"""
88 return dict(name=name, namepl=namepl, record=r, form=form)
93 def update(self, id, **kw):
94 """Save or create record to model"""
95 r = validate_set(id, kw)
96 flash(_(u'El %s fue actualizado.') % name)
97 raise redirect('../list')
99 @expose(template='kid:%s.templates.show' % __name__)
100 def show(self,id, **kw):
101 """Show record in model"""
103 return dict(name=name, namepl=namepl, record=r)
106 def delete(self, id):
107 """Destroy record in model"""
110 flash(_(u'El %s fue eliminado permanentemente.') % name)
111 raise redirect('../list')