1 # vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker :
4 from turbogears import controllers, expose, redirect
5 from turbogears import validate, flash, error_handler
6 from turbogears import validators as V
7 from turbogears import widgets as W
8 from turbogears import identity
9 from turbogears import paginate
10 from docutils.core import publish_parts
11 from sercom.subcontrollers import validate as val
12 from sercom.model import Tarea, Enunciado
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)
33 return val.validate_del(cls, name, id)
38 return [(0, _(u'<<General>>'))] + [(fk.id, fk.shortrepr())
39 for fk in fkcls.select()]
41 class CasoDePruebaForm(W.TableForm):
42 class Fields(W.WidgetsList):
43 nombre = W.TextField(label=_(u'Nombre'),
44 help_text=_(u'Requerido y único.'),
45 validator=V.UnicodeString(min=5, max=60, strip=True))
46 descripcion = W.TextField(label=_(u'Descripción'),
47 validator=V.UnicodeString(not_empty=False, max=255,
49 comando = W.TextField(label=_(u'Comando'),
50 validator=V.UnicodeString(not_empty=False, strip=True))
51 retorno = W.TextField(label=_(u'Código de retorno'),
52 validator=V.Int(not_empty=False, strip=True))
53 max_tiempo_cpu = W.TextField(label=_(u'Máximo tiempo de CPU'),
54 validator=V.Number(not_empty=False, strip=True))
56 javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")]
58 form = CasoDePruebaForm()
63 class TareaController(controllers.Controller, identity.SecureResource):
64 """Basic model admin interface"""
65 require = identity.has_permission('admin')
68 def default(self, tg_errors=None):
69 """handle non exist urls"""
70 raise redirect('list')
74 raise redirect('list')
76 @expose(template='kid:%s.templates.list' % __name__)
77 @validate(validators=dict(enunciado=V.Int))
78 def list(self, enunciado):
79 """List records in model"""
81 raise redirect("../list")
82 r = Enunciado.get(enunciado)
83 return dict(enunciado=r)
85 @expose(template='kid:%s.templates.new' % __name__)
87 """Create new records in model"""
88 return dict(name=name, namepl=namepl, form=form, values=kw)
93 def create(self, **kw):
94 """Save or create record to model"""
96 flash(_(u'Se creó un nuevo %s.') % name)
97 raise redirect('list')
99 @expose(template='kid:%s.templates.edit' % __name__)
100 def edit(self, id, **kw):
101 """Edit record in model"""
103 return dict(name=name, namepl=namepl, record=r, form=form)
108 def update(self, id, **kw):
109 """Save or create record to model"""
110 r = validate_set(id, kw)
111 flash(_(u'El %s fue actualizado.') % name)
112 raise redirect('../list')
114 @expose(template='kid:%s.templates.show' % __name__)
115 def show(self, id, **kw):
116 """Show record in model"""
118 if r.descripcion is None:
121 r.desc = publish_parts(r.descripcion, writer_name='html')['html_body']
122 return dict(name=name, namepl=namepl, record=r)
125 def delete(self, id):
126 """Destroy record in model"""
128 flash(_(u'El %s fue eliminado permanentemente.') % name)
129 raise redirect('../list')