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