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 *
15 from comandos import ComandoFuenteController
21 namepl = 'tareas fuente'
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 TareaFuenteForm(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 = TareaFuenteForm()
48 class TareaFuenteController(controllers.Controller, identity.SecureResource):
49 """Basic model admin interface"""
50 require = identity.has_permission('entregar')
52 comandos = ComandoFuenteController()
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__)
65 @identity.require(identity.has_permission('admin'))
67 """List records in model"""
69 return dict(records=r, name=name, namepl=namepl)
71 @expose(template='kid:%s.templates.new' % __name__)
72 @identity.require(identity.has_permission('admin'))
74 """Create new records in model"""
75 return dict(name=name, namepl=namepl, form=form, values=kw)
80 @identity.require(identity.has_permission('admin'))
81 def create(self, **kw):
82 """Save or create record to model"""
84 flash(_(u'Se creó un nuevo %s.') % name)
85 raise redirect('list')
87 @expose(template='kid:%s.templates.edit' % __name__)
88 @identity.require(identity.has_permission('admin'))
89 def edit(self, id, **kw):
90 """Edit record in model"""
92 return dict(name=name, namepl=namepl, record=r, form=form)
97 @identity.require(identity.has_permission('admin'))
98 def update(self, id, **kw):
99 """Save or create record to model"""
100 r = validate_set(id, kw)
101 flash(_(u'El %s fue actualizado.') % name)
102 raise redirect('../list')
104 @expose(template='kid:%s.templates.show' % __name__)
105 def show(self,id, **kw):
106 """Show record in model"""
108 return dict(name=name, namepl=namepl, record=r)
111 @identity.require(identity.has_permission('admin'))
112 def delete(self, id):
113 """Destroy record in model"""
116 flash(_(u'El %s fue eliminado permanentemente.') % name)
117 raise redirect('../list')