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 TareaFuente
14 from sqlobject import *
20 namepl = 'tareas fuente'
25 return val.validate_get(cls, name, id)
27 def validate_set(id, data):
28 return val.validate_set(cls, name, id, data)
30 def validate_new(data):
31 return val.validate_new(cls, name, data)
35 class TareaFuenteForm(W.TableForm):
36 class Fields(W.WidgetsList):
37 nombre = W.TextField(label=_(u'Nombre'),validator=V.UnicodeString(min=3, max=30, strip=True))
38 descripcion = W.TextField(label=_(u'Descripcion'),
39 validator=V.UnicodeString(not_empty=False, max=255, strip=True))
41 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")]
43 form = TareaFuenteForm()
47 class TareaFuenteController(controllers.Controller, identity.SecureResource):
48 """Basic model admin interface"""
49 require = identity.has_permission('admin')
52 def default(self, tg_errors=None):
53 """handle non exist urls"""
54 raise redirect('list')
58 raise redirect('list')
60 @expose(template='kid:%s.templates.list' % __name__)
63 """List records in model"""
65 return dict(records=r, name=name, namepl=namepl)
67 @expose(template='kid:%s.templates.new' % __name__)
69 """Create new records in model"""
70 return dict(name=name, namepl=namepl, form=form, values=kw)
75 def create(self, **kw):
76 """Save or create record to model"""
78 flash(_(u'Se creó un nuevo %s.') % name)
79 raise redirect('list')
81 @expose(template='kid:%s.templates.edit' % __name__)
82 def edit(self, id, **kw):
83 """Edit record in model"""
85 return dict(name=name, namepl=namepl, record=r, form=form)
90 def update(self, id, **kw):
91 """Save or create record to model"""
92 r = validate_set(id, kw)
93 flash(_(u'El %s fue actualizado.') % name)
94 raise redirect('../list')
96 @expose(template='kid:%s.templates.show' % __name__)
97 def show(self,id, **kw):
98 """Show record in model"""
100 return dict(name=name, namepl=namepl, record=r)
103 def delete(self, id):
104 """Destroy record in model"""
107 flash(_(u'El %s fue eliminado permanentemente.') % name)
108 raise redirect('../list')