From 58c42ffa3843a90e4f452846c8158b3f9a15232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Tue, 30 Sep 2014 21:23:22 -0300 Subject: [PATCH] =?UTF-8?q?Tratamento=20de=20exce=C3=A7=C3=A3o=20para=20pe?= =?UTF-8?q?rmitir=20cria=C3=A7=C3=A3o=20de=20banco=20de=20dados=20em=20amb?= =?UTF-8?q?iente=20DEV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/diagnosticos/admin.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sigi/apps/diagnosticos/admin.py b/sigi/apps/diagnosticos/admin.py index da15f9d..e1ef113 100644 --- a/sigi/apps/diagnosticos/admin.py +++ b/sigi/apps/diagnosticos/admin.py @@ -5,6 +5,7 @@ from eav.admin import BaseEntityAdmin, BaseSchemaAdmin from sigi.apps.diagnosticos.models import Diagnostico, Pergunta, Escolha, Equipe, Anexo, Categoria from sigi.apps.diagnosticos.forms import DiagnosticoForm from sigi.apps.contatos.models import UnidadeFederativa +from django.db.utils import OperationalError def publicar_diagnostico(self, request, queryset): @@ -66,15 +67,18 @@ class DiagnosticoAdmin(BaseEntityAdmin): # popula o eav fieldsets ordenando as categorias e as perguntas # para serem exibidas no admin - for categoria in Categoria.objects.all(): - # ordena as perguntas pelo title e utiliza o name no fieldset - perguntas_by_title = [(p.title, p.name) for p in categoria.perguntas.all()] - perguntas = [pergunta[1] for pergunta in sorted(perguntas_by_title)] - - eav_fieldsets += ((categoria, { - 'fields': tuple(perguntas), - 'classes': ['collapse'] - }),) + try: + for categoria in Categoria.objects.all(): + # ordena as perguntas pelo title e utiliza o name no fieldset + perguntas_by_title = [(p.title, p.name) for p in categoria.perguntas.all()] + perguntas = [pergunta[1] for pergunta in sorted(perguntas_by_title)] + + eav_fieldsets += ((categoria, { + 'fields': tuple(perguntas), + 'classes': ['collapse'] + }),) + except OperationalError: + pass # Hack to prevent Django.db.OperationalError on migrate/syncdb at creating new database def get_uf(self, obj): return '%s' % (obj.casa_legislativa.municipio.uf)