X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/6526a74b42e33e807f8e3846f38b28ef1f5de534..898fc8292d2ba43b2564d1f22bc6181d569adfe2:/sercom/subcontrollers/docente/__init__.py diff --git a/sercom/subcontrollers/docente/__init__.py b/sercom/subcontrollers/docente/__init__.py index a167d7a..ff7e61b 100644 --- a/sercom/subcontrollers/docente/__init__.py +++ b/sercom/subcontrollers/docente/__init__.py @@ -1,22 +1,30 @@ -# vim: set et sw=4 sts=4 encoding=utf-8 : +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : +#{{{ Imports +import cherrypy from turbogears import controllers, expose, redirect from turbogears import validate, validators, flash, error_handler -from sercom.model import Docente from turbogears.widgets import * 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 Docente +#}}} +#{{{ Configuración cls = Docente name = 'docente' namepl = name + 's' +#}}} +#{{{ Validación def validate_get(id): return val.validate_get(cls, name, id) def validate_set(id, data): return val.validate_set(cls, name, id, data) def validate_new(data): return val.validate_new(cls, name, data) +#}}} +#{{{ Formulario form = TableForm(fields=[ TextField(name='usuario', label=_(u'Usuario'), help_text=_(u'Requerido y único.'), @@ -42,7 +50,10 @@ form = TableForm(fields=[ #help_text=_(u'Si no está activo no puede ingresar al sistema.'), validator=validators.Bool(if_empty=1)), ]) +form.javascript.append(JSSource("MochiKit.DOM.focusOnLoad('form_usuario');")) +#}}} +#{{{ Controlador class DocenteController(controllers.Controller, identity.SecureResource): """Basic model admin interface""" require = identity.has_permission('admin') @@ -58,11 +69,10 @@ class DocenteController(controllers.Controller, identity.SecureResource): @expose(template='kid:%s.templates.list' % __name__) @paginate('records') - def list(self, **kw): + def list(self): """List records in model""" - f = kw.get('tg_flash', None) r = cls.select() - return dict(records=r, name=name, namepl=namepl, tg_flash=f) + return dict(records=r, name=name, namepl=namepl) @expose() def activate(self, id, activo): @@ -70,15 +80,14 @@ class DocenteController(controllers.Controller, identity.SecureResource): r = validate_get(id) try: r.activo = bool(int(activo)) - except ValueError, e: - raise redirect('../list', tg_flash=_(u'Acción inválida.')) - raise redirect('../list') + except ValueError: + raise cherrypy.NotFound + raise redirect('../../list') @expose(template='kid:%s.templates.new' % __name__) def new(self, **kw): """Create new records in model""" - f = kw.get('tg_flash', None) - return dict(name=name, namepl=namepl, form=form, tg_flash=f, values=kw) + return dict(name=name, namepl=namepl, form=form, values=kw) @validate(form=form) @error_handler(new) @@ -86,14 +95,14 @@ class DocenteController(controllers.Controller, identity.SecureResource): def create(self, **kw): """Save or create record to model""" validate_new(kw) - raise redirect('list', tg_flash=_(u'Se creó un nuevo %s.') % name) + flash(_(u'Se creó un nuevo %s.') % name) + raise redirect('list') @expose(template='kid:%s.templates.edit' % __name__) def edit(self, id, **kw): """Edit record in model""" r = validate_get(id) - return dict(name=name, namepl=namepl, record=r, form=form, - tg_flash=kw.get('tg_flash', None)) + return dict(name=name, namepl=namepl, record=r, form=form) @validate(form=form) @error_handler(edit) @@ -101,14 +110,17 @@ class DocenteController(controllers.Controller, identity.SecureResource): def update(self, id, **kw): """Save or create record to model""" r = validate_set(id, kw) - raise redirect('../list', - tg_flash=_(u'El %s fue actualizado.') % name) + flash(_(u'El %s fue actualizado.') % name) + raise redirect('../list') @expose(template='kid:%s.templates.show' % __name__) def show(self,id, **kw): """Show record in model""" r = validate_get(id) - r.obs = publish_parts(r.observaciones, writer_name='html')['html_body'] + if r.observaciones is None: + r.obs = '' + else: + r.obs = publish_parts(r.observaciones, writer_name='html')['html_body'] return dict(name=name, namepl=namepl, record=r) @expose() @@ -116,6 +128,7 @@ class DocenteController(controllers.Controller, identity.SecureResource): """Destroy record in model""" r = validate_get(id) r.destroySelf() - raise redirect('../list', - tg_flash=_(u'El %s fue eliminado permanentemente.') % name) + flash(_(u'El %s fue eliminado permanentemente.') % name) + raise redirect('../list') +#}}}