X-Git-Url: https://git.llucax.com/z.facultad/75.52/sercom.git/blobdiff_plain/d47dd9949d44d12944f557b0efd80459b857ce74..e9571fa510c7719a5b3e59a795fe8b7625112f3d:/sercom/subcontrollers/enunciado/__init__.py diff --git a/sercom/subcontrollers/enunciado/__init__.py b/sercom/subcontrollers/enunciado/__init__.py index 9527e83..7f5661f 100644 --- a/sercom/subcontrollers/enunciado/__init__.py +++ b/sercom/subcontrollers/enunciado/__init__.py @@ -1,14 +1,18 @@ -# vim: set et sw=4 sts=4 encoding=utf-8 : +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : +#{{{ Imports from turbogears import controllers, expose, redirect -from turbogears import validate, validators, flash, error_handler -from turbogears.widgets import * +from turbogears import validate, flash, error_handler +from turbogears import validators as V +from turbogears import widgets as W from turbogears import identity from turbogears import paginate from docutils.core import publish_parts from sercom.subcontrollers import validate as val from sercom.model import Enunciado, Docente +#}}} +#{{{ Configuración cls = Enunciado name = 'enunciado' namepl = name + 's' @@ -16,7 +20,9 @@ namepl = name + 's' fkcls = Docente fkname = 'autor' fknamepl = fkname + 'es' +#}}} +#{{{ Validación def validate_fk(data): fk = data.get(fkname + 'ID', None) if fk == 0: fk = None @@ -41,21 +47,28 @@ def validate_set(id, data): def validate_new(data): validate_fk(data) return val.validate_new(cls, name, data) +#}}} +#{{{ Formulario def get_options(): return [(0, _(u'--'))] + [(fk.id, fk.shortrepr()) for fk in fkcls.select()] -form = TableForm(fields=[ - TextField(name='nombre', label=_(u'Nombre'), - help_text=_(u'Requerido y único.'), - validator=validators.UnicodeString(min=5, max=60, strip=True)), - SingleSelectField(name=fkname+'ID', label=_(fkname.capitalize()), - options=get_options, validator=validators.Int(not_empty=False)), - TextField(name='descripcion', label=_(u'Descripción'), - validator=validators.UnicodeString(not_empty=False, max=255, strip=True)), -]) -form.javascript.append(JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")) - +class EnunciadoForm(W.TableForm): + class Fields(W.WidgetsList): + nombre = W.TextField(label=_(u'Nombre'), + help_text=_(u'Requerido y único.'), + validator=V.UnicodeString(min=5, max=60, strip=True)), + fk = W.SingleSelectField(name=fkname+'ID', label=_(fkname.capitalize()), + options=get_options, validator=V.Int(not_empty=False)), + descripcion = W.TextField(label=_(u'Descripción'), + validator=V.UnicodeString(not_empty=False, max=255, strip=True)), + fields = Fields() + javascript = [W.JSSource("MochiKit.DOM.focusOnLoad('form_nombre');")] + +form = EnunciadoForm() +#}}} + +#{{{ Controlador class EnunciadoController(controllers.Controller, identity.SecureResource): """Basic model admin interface""" require = identity.has_permission('admin') @@ -70,7 +83,7 @@ class EnunciadoController(controllers.Controller, identity.SecureResource): raise redirect('list') @expose(template='kid:%s.templates.list' % __name__) - @validate(validators=dict(autor=validators.Int)) + @validate(validators=dict(autor=V.Int)) @paginate('records') def list(self, autor=None): """List records in model""" @@ -126,4 +139,5 @@ class EnunciadoController(controllers.Controller, identity.SecureResource): r.destroySelf() flash(_(u'El %s fue eliminado permanentemente.') % name) raise redirect('../list') +#}}}