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('entregar')
52 comandos = ComandoPruebaController()
57 def default(self, tg_errors=None):
58 """handle non exist urls"""
59 raise redirect('list')
63 raise redirect('list')
65 @expose(template='kid:%s.templates.list' % __name__)
67 @identity.require(identity.has_permission('admin'))
69 """List records in model"""
71 return dict(records=r, name=name, namepl=namepl)
73 @expose(template='kid:%s.templates.new' % __name__)
74 @identity.require(identity.has_permission('admin'))
76 """Create new records in model"""
77 return dict(name=name, namepl=namepl, form=form, values=kw)
82 @identity.require(identity.has_permission('admin'))
83 def create(self, **kw):
84 """Save or create record to model"""
86 flash(_(u'Se creó un nuevo %s.') % name)
87 raise redirect('list')
89 @expose(template='kid:%s.templates.edit' % __name__)
90 @identity.require(identity.has_permission('admin'))
91 def edit(self, id, **kw):
92 """Edit record in model"""
94 return dict(name=name, namepl=namepl, record=r, form=form)
99 @identity.require(identity.has_permission('admin'))
100 def update(self, id, **kw):
101 """Save or create record to model"""
102 r = validate_set(id, kw)
103 flash(_(u'El %s fue actualizado.') % name)
104 raise redirect('../list')
106 @expose(template='kid:%s.templates.show' % __name__)
107 def show(self,id, **kw):
108 """Show record in model"""
110 return dict(name=name, namepl=namepl, record=r)
113 @identity.require(identity.has_permission('admin'))
114 def delete(self, id):
115 """Destroy record in model"""
118 flash(_(u'El %s fue eliminado permanentemente.') % name)
119 raise redirect('../list')