From: Leandro Lucarella Date: Mon, 5 Feb 2007 18:17:22 +0000 (+0000) Subject: Manejar bien error de registro duplicado al crear. X-Git-Url: https://git.llucax.com/software/sercom.git/commitdiff_plain/081f501efd6fd1c2833faafb45ed4f57fa4bb8c8 Manejar bien error de registro duplicado al crear. --- 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