Browse Source

Merge pull request #521 from interlegis/501-fix-parlamentar-base-vazia

Fix #501 Valida a tela de parlamentar caso a base esteja vazia
pull/516/head
Edward 9 years ago
committed by GitHub
parent
commit
80a13643b6
  1. 23
      sapl/parlamentares/views.py

23
sapl/parlamentares/views.py

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

Loading…
Cancel
Save