From 081f501efd6fd1c2833faafb45ed4f57fa4bb8c8 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 5 Feb 2007 18:17:22 +0000 Subject: [PATCH 1/1] Manejar bien error de registro duplicado al crear. --- sercom/subcontrollers/docente/__init__.py | 10 ++++++++-- sercom/subcontrollers/docente/templates/new.kid | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sercom/subcontrollers/docente/__init__.py b/sercom/subcontrollers/docente/__init__.py index e407081..c4dcfc5 100644 --- a/sercom/subcontrollers/docente/__init__.py +++ b/sercom/subcontrollers/docente/__init__.py @@ -70,14 +70,20 @@ class DocenteController(controllers.Controller, identity.SecureResource): @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) + try: + Docente(**kw) + except Exception, e: + raise redirect('new', tg_flash=_(u'No se pudo crear el nuevo %s, ' \ + 'probablemente ya existe uno con el mismo usuario (error: %s).' + % (name, e)), **kw) raise redirect('list', tg_flash=_(u'Se creó un nuevo %s.') % name) diff --git a/sercom/subcontrollers/docente/templates/new.kid b/sercom/subcontrollers/docente/templates/new.kid index 232f80d..c7e0d4b 100644 --- a/sercom/subcontrollers/docente/templates/new.kid +++ b/sercom/subcontrollers/docente/templates/new.kid @@ -9,7 +9,7 @@

Crear Nuevo Objeto

-

Formulario

+

Formulario


Cancelar -- 2.43.0