From f6571c8491010975ada4c272866c62f8b21ea0b3 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 1 Apr 2016 14:29:32 -0300 Subject: [PATCH] Arruma alguns detalhes. Ainda falta arrumar a paginacao, porque teve outro problema --- materia/forms.py | 36 +++++++++++++---- materia/views.py | 17 ++++---- .../materia/materialegislativa_filter.html | 2 +- templates/paginacao_pesquisa_materia.html | 39 +++++++++++++++++-- 4 files changed, 72 insertions(+), 22 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index e6c2724c2..f48090fce 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -567,6 +567,25 @@ class AutoriaForm(ModelForm): *args, **kwargs) +class RangeWidgetOverride(forms.MultiWidget): + def __init__(self, attrs=None): + widgets = (forms.DateInput( + format='%d/%m/%Y', + attrs={'class': 'dateinput'}), + forms.DateInput( + format='%d/%m/%Y', + attrs={'class': 'dateinput'})) + super(RangeWidgetOverride, self).__init__(widgets, attrs) + + def decompress(self, value): + if value: + return [value.start, value.stop] + return [None, None] + + def format_output(self, rendered_widgets): + return '-'.join(rendered_widgets) + + class MateriaLegislativaPesquisaFields(FilterSet): numero = django_filters.CharFilter(required=False, @@ -588,14 +607,16 @@ class MateriaLegislativaPesquisaFields(FilterSet): ) data_apresentacao = django_filters.DateFromToRangeFilter( - label=u'Data de Apresentação', - required=False, - help_text="") + label=u'Data de Apresentação (Inicial - Final)', + required=False, + help_text="", + widget=RangeWidgetOverride) data_publicacao = django_filters.DateFromToRangeFilter( - label=u'Data da Publicação', - required=False, - help_text="") + label=u'Data da Publicação (Inicial - Final)', + required=False, + help_text="", + widget=RangeWidgetOverride) autoria__autor = django_filters.ModelChoiceFilter( label='Autor', @@ -620,7 +641,6 @@ class MateriaLegislativaPesquisaFields(FilterSet): empty_label='Selecione', help_text="") - # # relatores são os parlamentares ativos? relatoria__parlamentar__id = django_filters.ModelChoiceFilter( label='Relator', required=False, @@ -664,6 +684,8 @@ class MateriaLegislativaPesquisaFields(FilterSet): lookup_expr='icontains', help_text="") + ORDER_BY_FIELD = "'numero', 'ano'" + class Meta: models = MateriaLegislativa fields = {'tipo', diff --git a/materia/views.py b/materia/views.py index 12839dc01..c95bc9ffa 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1223,32 +1223,29 @@ class MateriaLegislativaPesquisaView(FilterView): status_tramitacao = data.get('tramitacao__status') unidade_destino = data.get('tramitacao__unidade_tramitacao_destino') - + # import ipdb; ipdb.set_trace() if status_tramitacao and unidade_destino: lista = filtra_tramitacao_destino_and_status(status_tramitacao, unidade_destino) self.object_list = self.filterset.qs.filter( - id__in=lista).distinct().order_by('tipo', 'numero', 'ano') + id__in=lista).distinct().order_by elif status_tramitacao: lista = filtra_tramitacao_status(status_tramitacao) self.object_list = self.filterset.qs.filter( - id__in=lista).distinct().order_by('tipo', 'numero', 'ano') + id__in=lista).distinct() elif unidade_destino: lista = filtra_tramitacao_destino(unidade_destino) self.object_list = self.filterset.qs.filter( - id__in=lista).distinct().order_by('tipo', 'numero', 'ano') + id__in=lista).distinct() else: - self.object_list = self.filterset.qs.order_by( - 'tipo', 'numero', 'ano') + self.object_list = self.filterset.qs if (data and data.get('numero') is not None): - url = "&"+str(self.request.environ['QUERY_STRING']) - if url[:5] == "&page": - url = url[7:] + url = str(self.request.environ['QUERY_STRING']) else: - url = '' + url = None context = self.get_context_data(filter=self.filterset, object_list=self.object_list, diff --git a/templates/materia/materialegislativa_filter.html b/templates/materia/materialegislativa_filter.html index 94821d1ca..0c72225c5 100644 --- a/templates/materia/materialegislativa_filter.html +++ b/templates/materia/materialegislativa_filter.html @@ -9,7 +9,7 @@

Pesquisar Matéria



- {{ filter.form | crispy }} + {{ filter.form.as_p }}

diff --git a/templates/paginacao_pesquisa_materia.html b/templates/paginacao_pesquisa_materia.html index 380b0f015..0395ab951 100644 --- a/templates/paginacao_pesquisa_materia.html +++ b/templates/paginacao_pesquisa_materia.html @@ -1,12 +1,25 @@ + {% if is_paginated %} -{% endif %} +{% endif %} \ No newline at end of file