From b866b02cf9416be8e44e61f77147ad36c50df14e Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 12 Sep 2016 15:54:51 -0300 Subject: [PATCH] Fix #573 --- sapl/parlamentares/models.py | 13 +++++++++---- sapl/parlamentares/views.py | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sapl/parlamentares/models.py b/sapl/parlamentares/models.py index d4c8d817a..1dd4db07f 100644 --- a/sapl/parlamentares/models.py +++ b/sapl/parlamentares/models.py @@ -18,11 +18,16 @@ class Legislatura(models.Model): verbose_name = _('Legislatura') verbose_name_plural = _('Legislaturas') + def atual(self): + current_year = datetime.now().year + if(self.data_inicio.year <= current_year and + self.data_fim.year >= current_year): + return True + else: + return False + def __str__(self): - # XXX Usar id mesmo? Ou criar campo para nÂș legislatura? - current_date = datetime.now().year - if(self.data_inicio.year <= current_date and - self.data_fim.year >= current_date): + if self.atual(): current = ' (%s)' % _('Atual') else: current = '' diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 0f2a8edfb..8b8237007 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -341,7 +341,9 @@ class ParlamentarCrud(Crud): try: legislatura_id = int(self.request.GET['periodo']) except MultiValueDictKeyError: - legislatura_id = legislaturas.first().id + for l in Legislatura.objects.all(): + if l.atual(): + return l.id return legislatura_id else: return 0