From accfacb2c3157f66330d4bd5d0bd15f56bfe7168 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Tue, 27 Feb 2007 06:54:04 +0000 Subject: [PATCH 1/1] cleanup ajax y mejor manejo de errores --- sercom/subcontrollers/grupo/__init__.py | 16 ++++++++++++---- sercom/widgets.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sercom/subcontrollers/grupo/__init__.py b/sercom/subcontrollers/grupo/__init__.py index fded213..8042b7c 100644 --- a/sercom/subcontrollers/grupo/__init__.py +++ b/sercom/subcontrollers/grupo/__init__.py @@ -11,7 +11,7 @@ from turbogears import paginate from docutils.core import publish_parts from sercom.subcontrollers import validate as val from sercom.model import Curso, AlumnoInscripto, Docente, Grupo, Alumno -from sqlobject import AND +from sqlobject import * from sercom.widgets import * @@ -70,7 +70,10 @@ ajax = u""" function procesar(result) { l = MochiKit.DOM.getElement('form_responsable_info'); - l.innerHTML = result.msg; + if (result.error) + l.innerHTML = result.msg; + else + l.innerHTML = result.msg.value; } function buscar_alumno() @@ -220,12 +223,17 @@ class GrupoController(controllers.Controller, identity.SecureResource): @expose('json') def get_inscripto(self, cursoid, padron): - msg = 'No existe el alumno %s en el curso seleccionado.' % padron + msg = u'' error=False try: # Busco el alumno inscripto alumno = AlumnoInscripto.selectBy(curso=cursoid, alumno=Alumno.byUsuario(padron)).getOne() - msg = alumno.alumno.nombre + msg = {} + msg['id'] = alumno.id + msg['value'] = alumno.alumno.nombre + except SQLObjectNotFound: + msg = 'No existe el alumno %s en el curso seleccionado.' % padron + error=True except Exception, (inst): msg = u"""Se ha producido un error inesperado al buscar el registro:\n %s""" % str(inst) error = True diff --git a/sercom/widgets.py b/sercom/widgets.py index c3ccea5..b4b7e13 100644 --- a/sercom/widgets.py +++ b/sercom/widgets.py @@ -28,7 +28,7 @@ AlumnoMultiSelectAjax = ''' alert(results.msg); return; } - MochiKit.DOM.appendChildNodes(lista, OPTION(results.msg)); + MochiKit.DOM.appendChildNodes(lista, OPTION({'value':results.msg.id}, results.msg.value)); } function _on_alumno_get_error(results) -- 2.43.0