X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/59972c6fd03ea093bd26eca762a7f4fa5a1320dd..9bc552cd8bca7a9c463d5c200bde0720238d6e56:/sercom/subcontrollers/validate.py?ds=sidebyside diff --git a/sercom/subcontrollers/validate.py b/sercom/subcontrollers/validate.py index 67b749a..345d92b 100644 --- a/sercom/subcontrollers/validate.py +++ b/sercom/subcontrollers/validate.py @@ -2,31 +2,27 @@ __all__ = ('validate_get', 'validate_set', 'validate_new') -from turbogears import redirect +from turbogears import redirect, flash +from cherrypy import NotFound def validate_get(cls, name, id, url='../list'): try: - id = int(id) - except ValueError: - raise redirect(url, tg_flash=_(u'Identificador inválido: %s.') % id) - try: - return cls.get(id) - except LookupError: - raise redirect(url, tg_flash=_(u'No existe %s con identificador %d') - % (name, id)) + return cls.get(int(id)) + except (ValueError, LookupError): + raise NotFound def validate_set(cls, name, id, data, url='../edit'): r = validate_get(cls, name, id) try: r.set(**data) except Exception, e: - raise redirect('%s/%s' % (url, id), tg_flash=_(u'No se pudo ' \ - 'modificar el %s (error: %s).') % (name, e), **data) + flash(_(u'No se pudo modificar el %s (error: %s).') % (name, e)) + raise redirect('%s/%s' % (url, id), **data) def validate_new(cls, name, data, url='new'): try: return cls(**data) except Exception, e: - raise redirect(url, tg_flash=_(u'No se pudo crear el nuevo %s ' \ - '(error: %s).') % (name, e), **data) + flash(_(u'No se pudo crear el nuevo %s (error: %s).') % (name, e)) + raise redirect(url, **data)