Browse Source

Fix #2180 (#2181)

* Fix #2180

* Update views.py

Adiciona o object_list para ordenação
pull/2169/merge
Mariana Mendes 6 years ago
committed by Edward
parent
commit
b3e0cdc6ec
  1. 6
      sapl/norma/forms.py
  2. 6
      sapl/norma/views.py
  3. 26
      sapl/utils.py

6
sapl/norma/forms.py

@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa
from sapl.settings import MAX_DOC_UPLOAD_SIZE
from sapl.utils import RANGE_ANOS, RangeWidgetOverride
from sapl.utils import NormaPesquisaOrderingFilter, RANGE_ANOS, RangeWidgetOverride
from .models import (AnexoNormaJuridica, AssuntoNorma, NormaJuridica, NormaRelacionada,
TipoNormaJuridica)
@ -55,6 +55,8 @@ class NormaFilterSet(django_filters.FilterSet):
assuntos = django_filters.ModelChoiceFilter(
queryset=AssuntoNorma.objects.all())
o = NormaPesquisaOrderingFilter()
class Meta:
model = NormaJuridica
fields = ['tipo', 'numero', 'ano', 'data',
@ -65,7 +67,7 @@ class NormaFilterSet(django_filters.FilterSet):
row1 = to_row([('tipo', 4), ('numero', 4), ('ano', 4)])
row2 = to_row([('data', 6), ('data_publicacao', 6)])
row3 = to_row([('ementa', 8), ('assuntos', 4)])
row3 = to_row([('ementa', 6), ('assuntos', 6), ('o',6)])
self.form.helper = FormHelper()
self.form.helper.form_method = 'GET'

6
sapl/norma/views.py

@ -86,6 +86,12 @@ class NormaPesquisaView(FilterView):
context['title'] = _('Pesquisar Norma Jurídica')
self.filterset.form.fields['o'].label = _('Ordenação')
qs = self.object_list
if 'o' in self.request.GET and not self.request.GET['o']:
qs = qs.order_by('-ano', 'tipo', '-numero')
qr = self.request.GET.copy()
if 'page' in qr:

26
sapl/utils.py

@ -437,6 +437,32 @@ class MateriaPesquisaOrderingFilter(django_filters.OrderingFilter):
return super().filter(qs, _value)
class NormaPesquisaOrderingFilter(django_filters.OrderingFilter):
choices = (
('', 'Selecione'),
('dataC', 'Data, Tipo, Ano, Numero - Ordem Crescente'),
('dataD', 'Data, Tipo, Ano, Numero - Ordem Decrescente'),
('tipoC', 'Tipo, Ano, Numero, Data - Ordem Crescente'),
('tipoD', 'Tipo, Ano, Numero, Data - Ordem Decrescente')
)
order_by_mapping = {
'': [],
'dataC': ['data', 'tipo', 'ano', 'numero'],
'dataD': ['-data', '-tipo', '-ano', '-numero'],
'tipoC': ['tipo', 'ano', 'numero', 'data'],
'tipoD': ['-tipo', '-ano', '-numero', '-data'],
}
def __init__(self, *args, **kwargs):
kwargs['choices'] = self.choices
super(NormaPesquisaOrderingFilter, self).__init__(*args, **kwargs)
def filter(self, qs, value):
_value = self.order_by_mapping[value[0]] if value else value
return super().filter(qs, _value)
class AnoNumeroOrderingFilter(django_filters.OrderingFilter):
choices = (('DEC', 'Ordem Decrescente'),

Loading…
Cancel
Save