Browse Source

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

pull/282/head
Eduardo Calil 9 years ago
parent
commit
f6571c8491
  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

@ -567,6 +567,25 @@ class AutoriaForm(ModelForm):
*args, **kwargs) *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): class MateriaLegislativaPesquisaFields(FilterSet):
numero = django_filters.CharFilter(required=False, numero = django_filters.CharFilter(required=False,
@ -588,14 +607,16 @@ class MateriaLegislativaPesquisaFields(FilterSet):
) )
data_apresentacao = django_filters.DateFromToRangeFilter( data_apresentacao = django_filters.DateFromToRangeFilter(
label=u'Data de Apresentação', label=u'Data de Apresentação (Inicial - Final)',
required=False, required=False,
help_text="") help_text="",
widget=RangeWidgetOverride)
data_publicacao = django_filters.DateFromToRangeFilter( data_publicacao = django_filters.DateFromToRangeFilter(
label=u'Data da Publicação', label=u'Data da Publicação (Inicial - Final)',
required=False, required=False,
help_text="") help_text="",
widget=RangeWidgetOverride)
autoria__autor = django_filters.ModelChoiceFilter( autoria__autor = django_filters.ModelChoiceFilter(
label='Autor', label='Autor',
@ -620,7 +641,6 @@ class MateriaLegislativaPesquisaFields(FilterSet):
empty_label='Selecione', empty_label='Selecione',
help_text="") help_text="")
# # relatores são os parlamentares ativos?
relatoria__parlamentar__id = django_filters.ModelChoiceFilter( relatoria__parlamentar__id = django_filters.ModelChoiceFilter(
label='Relator', label='Relator',
required=False, required=False,
@ -664,6 +684,8 @@ class MateriaLegislativaPesquisaFields(FilterSet):
lookup_expr='icontains', lookup_expr='icontains',
help_text="") help_text="")
ORDER_BY_FIELD = "'numero', 'ano'"
class Meta: class Meta:
models = MateriaLegislativa models = MateriaLegislativa
fields = {'tipo', fields = {'tipo',

17
materia/views.py

@ -1223,32 +1223,29 @@ class MateriaLegislativaPesquisaView(FilterView):
status_tramitacao = data.get('tramitacao__status') status_tramitacao = data.get('tramitacao__status')
unidade_destino = data.get('tramitacao__unidade_tramitacao_destino') unidade_destino = data.get('tramitacao__unidade_tramitacao_destino')
# import ipdb; ipdb.set_trace()
if status_tramitacao and unidade_destino: if status_tramitacao and unidade_destino:
lista = filtra_tramitacao_destino_and_status(status_tramitacao, lista = filtra_tramitacao_destino_and_status(status_tramitacao,
unidade_destino) unidade_destino)
self.object_list = self.filterset.qs.filter( 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: elif status_tramitacao:
lista = filtra_tramitacao_status(status_tramitacao) lista = filtra_tramitacao_status(status_tramitacao)
self.object_list = self.filterset.qs.filter( self.object_list = self.filterset.qs.filter(
id__in=lista).distinct().order_by('tipo', 'numero', 'ano') id__in=lista).distinct()
elif unidade_destino: elif unidade_destino:
lista = filtra_tramitacao_destino(unidade_destino) lista = filtra_tramitacao_destino(unidade_destino)
self.object_list = self.filterset.qs.filter( self.object_list = self.filterset.qs.filter(
id__in=lista).distinct().order_by('tipo', 'numero', 'ano') id__in=lista).distinct()
else: else:
self.object_list = self.filterset.qs.order_by( self.object_list = self.filterset.qs
'tipo', 'numero', 'ano')
if (data and data.get('numero') is not None): if (data and data.get('numero') is not None):
url = "&"+str(self.request.environ['QUERY_STRING']) url = str(self.request.environ['QUERY_STRING'])
if url[:5] == "&page":
url = url[7:]
else: else:
url = '' url = None
context = self.get_context_data(filter=self.filterset, context = self.get_context_data(filter=self.filterset,
object_list=self.object_list, object_list=self.object_list,

2
templates/materia/materialegislativa_filter.html

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

39
templates/paginacao_pesquisa_materia.html

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