X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/7bee4072574324ca7b3e6d8dc6deec589b13126f..d9cd422b175f8e5ebb8c98d974c139586da8217d:/sercom/subcontrollers/docente/__init__.py?ds=sidebyside diff --git a/sercom/subcontrollers/docente/__init__.py b/sercom/subcontrollers/docente/__init__.py index e01023d..c93184d 100644 --- a/sercom/subcontrollers/docente/__init__.py +++ b/sercom/subcontrollers/docente/__init__.py @@ -7,14 +7,19 @@ 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 cls = Docente name = 'docente' namepl = name + 's' +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) + form = TableForm(fields=[ TextField(name='usuario', label=_(u'Usuario'), - help_text=_(u'Requerido.'), + help_text=_(u'Requerido y único.'), validator=validators.UnicodeString(min=3, max=10, strip=True)), TextField(name='nombre', label=_(u'Nombre'), help_text=_(u'Requerido.'), @@ -38,11 +43,6 @@ form = TableForm(fields=[ validator=validators.Bool(if_empty=1)), ]) -def minimize(text, size=15): - if text is not None and len(text) > size: - text = text[:size] + '...' - return text - class DocenteController(controllers.Controller, identity.SecureResource): """Basic model admin interface""" require = identity.has_permission('admin') @@ -62,57 +62,60 @@ class DocenteController(controllers.Controller, identity.SecureResource): """List records in model""" f = kw.get('tg_flash', None) r = cls.select() - return dict(records=r, name=name, namepl=namepl, tg_flash=f) + @expose() + def activate(self, id, activo): + """Save or create record to model""" + 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') + @expose(template='kid:sercom.subcontrollers.%s.templates.new' % name) def new(self, **kw): """Create new records in model""" - return dict(name=name, namepl=namepl, form=form) + f = kw.get('tg_flash', None) + return dict(name=name, namepl=namepl, form=form, tg_flash=f, values=kw) @validate(form=form) @error_handler(new) @expose() def create(self, **kw): """Save or create record to model""" - Docente(**kw) - + validate_new(kw) raise redirect('list', tg_flash=_(u'Se creó un nuevo %s.') % name) @expose(template='kid:sercom.subcontrollers.%s.templates.edit' % name) def edit(self, id, **kw): """Edit record in model""" - try: - r = cls.get(int(id)) - except LookupError: - flash = _('No existe el docente con identificador %d.') % id - - return dict(name=name, namepl=namepl, record=r, form=form) + r = validate_get(id) + return dict(name=name, namepl=namepl, record=r, form=form, + tg_flash=kw.get('tg_flash', None)) @validate(form=form) @error_handler(edit) @expose() def update(self, id, **kw): """Save or create record to model""" - record = cls.get(int(id)) - record.set(**kw) - + r = validate_set(id, kw) raise redirect('../list', tg_flash=_(u'El %s fue actualizado.') % name) @expose(template='kid:sercom.subcontrollers.%s.templates.show' % name) def show(self,id, **kw): """Show record in model""" - r = cls.get(int(id)) + r = validate_get(id) r.obs = publish_parts(r.observaciones, writer_name='html')['html_body'] - return dict(name=name, namepl=namepl, record=r) @expose() def delete(self, id): """Destroy record in model""" - cls.delete(int(id)) - + r = validate_get(id) + r.destroySelf() raise redirect('../list', tg_flash=_(u'El %s fue eliminado permanentemente.') % name)