From f916ed83df5fde36215fc8548e7196899d0da723 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 10 Oct 2016 09:34:48 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20quebra=20em=20sessao/create=20quando?= =?UTF-8?q?=20n=C3=A3o=20h=C3=A1=20legislatura=20cadastrada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/sessao/views.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index b8a6da598..553026cec 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -449,8 +449,14 @@ class SessaoCrud(Crud): return self.search_url def get_initial(self): - legislatura = Legislatura.objects.order_by('-data_inicio')[0] - return {'legislatura': legislatura} + legislatura = Legislatura.objects.order_by('-data_inicio') + if legislatura: + return {'legislatura': legislatura[0]} + else: + msg = _('Cadastre alguma legislatura antes de adicionar ' + + 'uma sessão plenária!') + messages.add_message(self.request, messages.ERROR, msg) + return {} class SessaoPermissionMixin(PermissionRequiredForAppCrudMixin,