diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 629c6f50f..910a1c655 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -1,4 +1,5 @@ from django.contrib import messages +from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect from django.utils.datastructures import MultiValueDictKeyError @@ -114,17 +115,21 @@ class ParlamentarCrud(Crud): legislaturas = Legislatura.objects.all().order_by( '-data_inicio', '-data_fim') - try: - legislatura_id = int(self.request.GET['periodo']) - except MultiValueDictKeyError: - legislatura_id = legislaturas.first().id - - return legislatura_id + if legislaturas: + try: + legislatura_id = int(self.request.GET['periodo']) + except MultiValueDictKeyError: + legislatura_id = legislaturas.first().id + return legislatura_id + else: + return 0 def get_queryset(self): - mandatos = Mandato.objects.filter( - legislatura_id=self.take_legislatura_id()) - return mandatos + if self.take_legislatura_id() != 0: + mandatos = Mandato.objects.filter( + legislatura_id=self.take_legislatura_id()) + return mandatos + return [] def get_rows(self, object_list): parlamentares = []