From dee81594ebc87d3148dd5c8d01d13f32afab50cb Mon Sep 17 00:00:00 2001 From: Leandro Roberto da Silva Date: Tue, 1 Nov 2016 15:15:47 -0200 Subject: [PATCH] =?UTF-8?q?Atualiza=20vers=C3=A3o=20do=20django-filter=20(?= =?UTF-8?q?#776)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * altera travis para testar com 3.5.2 * retorna python para 3.4.3 * downgrading django-filter to 0.11 * altera versão do django-filter para ult do pypi * ref pesquisas para atualização do django-filter --- requirements/requirements.txt | 2 +- sapl/materia/forms.py | 36 ++++++----------------- sapl/protocoloadm/forms.py | 47 +++++------------------------- sapl/sessao/forms.py | 17 ++++------- sapl/utils.py | 54 ++++++++++++++++++++++++++++++++--- 5 files changed, 72 insertions(+), 84 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 9ddd7a255..4387cb37d 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -8,7 +8,7 @@ django-compressor==2.0 django-crispy-forms==1.6.0 django-extensions==1.6.7 django-extra-views==0.8.0 -django-filter==0.13.0 +django-filter==0.15.3 django-floppyforms==1.6.2 django-model-utils==2.5 django-sass-processor==0.4.6 diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index b9a3db1ed..b887569f4 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1,8 +1,7 @@ -import os from datetime import date, datetime +import os -import django_filters from crispy_forms.bootstrap import (Alert, FormActions, InlineCheckboxes, InlineRadios) from crispy_forms.helper import FormHelper @@ -18,8 +17,8 @@ from django.db.models import Max from django.forms import ModelForm, widgets from django.forms.forms import Form from django.utils.translation import ugettext_lazy as _ +import django_filters -import sapl from sapl.base.models import Autor from sapl.comissoes.models import Comissao from sapl.crispy_layout_mixin import (SaplFormLayout, form_actions, to_column, @@ -32,7 +31,9 @@ from sapl.protocoloadm.models import Protocolo from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, ChoiceWithoutValidationField, RangeWidgetOverride, - autor_label, autor_modal, models_with_gr_for_model) + autor_label, autor_modal, models_with_gr_for_model, + MateriaPesquisaOrderingFilter) +import sapl from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, DocumentoAcessorio, MateriaLegislativa, Numeracao, @@ -444,6 +445,8 @@ class MateriaLegislativaFilterSet(django_filters.FilterSet): label=u'Ano da Matéria', choices=em_tramitacao) + o = MateriaPesquisaOrderingFilter() + class Meta: model = MateriaLegislativa fields = ['numero', @@ -453,7 +456,7 @@ class MateriaLegislativaFilterSet(django_filters.FilterSet): 'data_apresentacao', 'data_publicacao', 'autoria__autor__tipo', - # 'autoria__autor__partido', + # FIXME 'autoria__autor__partido', 'relatoria__parlamentar_id', 'local_origem_externa', 'tramitacao__unidade_tramitacao_destino', @@ -461,29 +464,6 @@ class MateriaLegislativaFilterSet(django_filters.FilterSet): 'em_tramitacao', ] - order_by = ( - ('', '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_apresentacao', 'tipo__sigla', 'ano', 'numero'], - 'dataD': ['-data_apresentacao', '-tipo__sigla', '-ano', '-numero'], - 'tipoC': ['tipo__sigla', 'ano', 'numero', 'data_apresentacao'], - 'tipoD': ['-tipo__sigla', '-ano', '-numero', '-data_apresentacao'], - } - - def get_order_by(self, order_value): - if order_value in self.order_by_mapping: - return self.order_by_mapping[order_value] - else: - return super(MateriaLegislativaFilterSet, - self).get_order_by(order_value) - def __init__(self, *args, **kwargs): super(MateriaLegislativaFilterSet, self).__init__(*args, **kwargs) diff --git a/sapl/protocoloadm/forms.py b/sapl/protocoloadm/forms.py index 0315d6f1c..c3bab49e7 100644 --- a/sapl/protocoloadm/forms.py +++ b/sapl/protocoloadm/forms.py @@ -1,6 +1,5 @@ from datetime import datetime -import django_filters from crispy_forms.bootstrap import InlineRadios from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Fieldset, Layout, Submit @@ -9,17 +8,19 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import models from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ +import django_filters from sapl.base.models import Autor from sapl.crispy_layout_mixin import form_actions, to_row from sapl.materia.models import UnidadeTramitacao from sapl.utils import (RANGE_ANOS, RangeWidgetOverride, autor_label, - autor_modal) + autor_modal, AnoNumeroOrderingFilter) from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, TipoDocumentoAdministrativo, TramitacaoAdministrativo) + TIPOS_PROTOCOLO = [('0', 'Enviado'), ('1', 'Recebido'), ('', 'Ambos')] NATUREZA_PROCESSO = [('', 'Ambos'), @@ -68,6 +69,8 @@ class ProtocoloFilterSet(django_filters.FilterSet): widget=forms.Select( attrs={'class': 'selector'})) + o = AnoNumeroOrderingFilter() + class Meta: model = Protocolo fields = ['numero', @@ -76,25 +79,6 @@ class ProtocoloFilterSet(django_filters.FilterSet): 'tipo_materia', ] - order_by = ( - ('', 'Selecione'), - ('CRE', 'Ordem Crescente'), - ('DEC', 'Ordem Decrescente'), - ) - - order_by_mapping = { - '': [], - 'CRE': ['ano', 'numero'], - 'DEC': ['-ano', '-numero'], - } - - def get_order_by(self, order_value): - if order_value in self.order_by_mapping: - return self.order_by_mapping[order_value] - else: - return super(ProtocoloFilterSet, - self).get_order_by(order_value) - def __init__(self, *args, **kwargs): super(ProtocoloFilterSet, self).__init__(*args, **kwargs) @@ -162,6 +146,8 @@ class DocumentoAdministrativoFilterSet(django_filters.FilterSet): interessado = django_filters.CharFilter(lookup_expr='icontains') + o = AnoNumeroOrderingFilter() + class Meta: model = DocumentoAdministrativo fields = ['tipo', @@ -171,25 +157,6 @@ class DocumentoAdministrativoFilterSet(django_filters.FilterSet): 'tramitacaoadministrativo__unidade_tramitacao_destino', 'tramitacaoadministrativo__status'] - order_by = ( - ('', 'Selecione'), - ('CRE', 'Ordem Crescente'), - ('DEC', 'Ordem Decrescente'), - ) - - order_by_mapping = { - '': [], - 'CRE': ['ano', 'numero'], - 'DEC': ['-ano', '-numero'], - } - - def get_order_by(self, order_value): - if order_value in self.order_by_mapping: - return self.order_by_mapping[order_value] - else: - return super(DocumentoAdministrativoFilterSet, - self).get_order_by(order_value) - def __init__(self, *args, **kwargs): super(DocumentoAdministrativoFilterSet, self).__init__(*args, **kwargs) diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index c99691656..988a0920b 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -1,18 +1,19 @@ from datetime import datetime -import django_filters from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Fieldset, Layout from django import forms from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ +import django_filters from sapl.crispy_layout_mixin import form_actions, to_row from sapl.materia.forms import MateriaLegislativaFilterSet from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.parlamentares.models import Parlamentar -from sapl.utils import RANGE_DIAS_MES, RANGE_MESES, autor_label, autor_modal +from sapl.utils import RANGE_DIAS_MES, RANGE_MESES, autor_label, autor_modal,\ + MateriaPesquisaOrderingFilter from .models import (Bancada, ExpedienteMateria, Orador, OradorExpediente, OrdemDia, SessaoPlenaria, SessaoPlenariaPresenca) @@ -206,6 +207,8 @@ class SessaoPlenariaFilterSet(django_filters.FilterSet): class AdicionarVariasMateriasFilterSet(MateriaLegislativaFilterSet): + o = MateriaPesquisaOrderingFilter() + class Meta: model = MateriaLegislativa fields = ['numero', @@ -215,20 +218,12 @@ class AdicionarVariasMateriasFilterSet(MateriaLegislativaFilterSet): 'data_apresentacao', 'data_publicacao', 'autoria__autor__tipo', - # 'autoria__autor__partido', + # FIXME 'autoria__autor__partido', 'relatoria__parlamentar_id', 'local_origem_externa', 'em_tramitacao', ] - order_by = ( - ('', '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') - ) - def __init__(self, *args, **kwargs): super(MateriaLegislativaFilterSet, self).__init__(*args, **kwargs) diff --git a/sapl/utils.py b/sapl/utils.py index 3969cfb74..ecf91e613 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,11 +1,10 @@ -import hashlib -import logging -import re from datetime import date from functools import wraps from unicodedata import normalize as unicodedata_normalize +import hashlib +import logging +import re -import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms @@ -17,10 +16,13 @@ from django.contrib.contenttypes.fields import (GenericForeignKey, GenericRel, from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput +import django_filters +import magic from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR + sapl_logger = logging.getLogger(BASE_DIR.name) @@ -466,6 +468,50 @@ def permissao_tb_aux(self): """ +class MateriaPesquisaOrderingFilter(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_apresentacao', 'tipo__sigla', 'ano', 'numero'], + 'dataD': ['-data_apresentacao', '-tipo__sigla', '-ano', '-numero'], + 'tipoC': ['tipo__sigla', 'ano', 'numero', 'data_apresentacao'], + 'tipoD': ['-tipo__sigla', '-ano', '-numero', '-data_apresentacao'], + } + + def __init__(self, *args, **kwargs): + kwargs['choices'] = self.choices + super(MateriaPesquisaOrderingFilter, self).__init__(*args, **kwargs) + + def filter(self, qs, value): + return super().filter(qs, self.order_by_mapping[value[0]]) + + +class AnoNumeroOrderingFilter(django_filters.OrderingFilter): + + choices = (('', 'Selecione...'), + ('CRE', 'Ordem Crescente'), + ('DEC', 'Ordem Decrescente'),) + order_by_mapping = { + '': [], + 'CRE': ['ano', 'numero'], + 'DEC': ['-ano', '-numero'], + } + + def __init__(self, *args, **kwargs): + kwargs['choices'] = self.choices + super(AnoNumeroOrderingFilter, self).__init__(*args, **kwargs) + + def filter(self, qs, value): + return super().filter(qs, self.order_by_mapping[value[0]]) + + def gerar_hash_arquivo(arquivo, pk, block_size=2**20): md5 = hashlib.md5() arq = open(arquivo, 'rb')