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..fda746e0e 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -332,6 +332,7 @@ class ParlamentarCrud(Crud): class ListView(CrudListView): template_name = "parlamentares/parlamentares_list.html" paginate_by = None + ordering = '-nome_parlamentar' def take_legislatura_id(self): legislaturas = Legislatura.objects.all().order_by( @@ -341,7 +342,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 @@ -349,7 +352,8 @@ class ParlamentarCrud(Crud): def get_queryset(self): if self.take_legislatura_id() != 0: mandatos = Mandato.objects.filter( - legislatura_id=self.take_legislatura_id()) + legislatura_id=self.take_legislatura_id()).order_by( + 'parlamentar__nome_parlamentar') return mandatos return [] diff --git a/sapl/templates/base.html b/sapl/templates/base.html index df70b2252..eebffba2e 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -42,13 +42,12 @@