Browse Source

Arruma alguns detalhes. Ainda falta arrumar a paginacao, porque teve outro problema

pull/282/head
Eduardo Calil 9 years ago
parent
commit
803eb0c2c1
  1. 36
      materia/forms.py
  2. 17
      materia/views.py
  3. 2
      templates/materia/materialegislativa_filter.html
  4. 39
      templates/paginacao_pesquisa_materia.html

36
materia/forms.py

@ -578,6 +578,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,
@ -599,14 +618,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',
@ -631,7 +652,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,
@ -675,6 +695,8 @@ class MateriaLegislativaPesquisaFields(FilterSet):
lookup_expr='icontains',
help_text="")
ORDER_BY_FIELD = "'numero', 'ano'"
class Meta:
models = MateriaLegislativa
fields = {'tipo',

17
materia/views.py

@ -1228,32 +1228,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,

2
templates/materia/materialegislativa_filter.html

@ -9,7 +9,7 @@
<h1><b>Pesquisar Matéria</b></h1>
<br></br>
<form action="" method="get">
{{ filter.form | crispy }}
{{ filter.form.as_p }}
<input type="submit" value="Pesquisar" />
</form>
<p></p>

39
templates/paginacao_pesquisa_materia.html

@ -1,12 +1,25 @@
{% if is_paginated %}
<nav class="text-center">
<ul class="pagination">
{% if page_obj.has_previous %}
{% if filter_url %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}{{filter_url}}">
<a class="page-link" href="?page={{page_obj.previous_page_number}}">
<span class="pager-prev">Anterior</span>
</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="?{{filter_url}}">
<span class="pager-prev">Anterior</span>
</a>
</li>
{% endif %}
{% else %}
<li class="pager-prev disabled"><a href="">Anterior</a></li>
{% endif %}
@ -17,21 +30,39 @@
<a class="page-link" href="">...</a>
</li>
{% else %}
{% if filter_url %}
<li {% if page == page_obj.number %} class="page-item active" {% endif %}>
<a class="page-link" href="?{{filter_url}}">{{ page }}</a>
</li>
{% else %}
<li {% if page == page_obj.number %} class="page-item active" {% endif %}>
<a class="page-link" href="?page={{ page }}{{filter_url}}">{{ page }}</a>
<a class="page-link" href="?page={{ page }}">{{ page }}</a>
</li>
{% endif %}
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
{% if filter_url %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}{{filter_url}}">
<a class="page-link" href="?page={{page_obj.next_page_number}}{{filter_url}}">
<span class="pager-next">Próxima</span>
</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="?page={{page_obj.next_page_number}}{{filter_url}}">
<span class="pager-next">Próxima</span>
</a>
</li>
{% endif %}
{% else %}
<li class="pager-next disabled"><a href="">Próxima</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
{% endif %}
Loading…
Cancel
Save